Skip to content

Preset position some elements #2398

Closed
Closed

Description

@r0otx

Hey, thanks for this cool library! I have a question. There is a list of 5 elements. The first and last elements are fixed and cannot be moved. The elements in the middle can move relative to each other. The server returns their positions when requested. How after getting the positions of the elements, I can sort them relative to each other.

Activity

  1. r0otx commented on Aug 18, 2024

    @r0otx
    Author

    I'm was resolve this next method.

    Use dataIdAttr and set unique id for per element in list:

    <li data-item-id="el1"> El1 </li>
    <li data-item-id="el2"> El2 </li>
    <li data-item-id="el3"> El3 </li>
    

    Create string array with this elements ids:

    const orderElements = ["el1", "el2", "el3"];

    Use store in useSortable:

        store: {
          get() {
            return orderElements;
          },
          set(sortable) {
            orderElements = sortable.toArray();
          },
        },
    

    When init my app, I'm sort array how send me elements position my backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions