Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there anyway to get the old and new index of the moved item? #559

Open
YousefJalali opened this issue Apr 17, 2024 · 6 comments
Open
Labels
question Further information is requested

Comments

@YousefJalali
Copy link

is there anyway to get the old and new index of the moved item in the finalized event? it will be much better to send the old and new index to the server and do a swap there instead of sending the whole list.

@isaacHagoel
Copy link
Owner

The lib has the info about the original index but it could be an index in a different list (if you have more than one). It is not included in the event atm.
With that said, it is easy to get it on your own with just a few lines of code.
In the consider event check for the trigger and if it is DRAG_STARTED grab the id property from the event (the id of the dragged element) and find its index in the list before mutating the list. Use that id in the finalize event to find the new index.

@isaacHagoel isaacHagoel added the question Further information is requested label Apr 17, 2024
@gregg-cbs
Copy link

gregg-cbs commented Dec 13, 2024

This library should tell you the index where you moved from and where you are moving to. Its the basic concept of sorting. You need to know the from and to indexes to update the sort orders in the database appropriately.

@gregg-cbs
Copy link

Also looking at this payload, there is nothing in here about the original index:
image

@isaacHagoel
Copy link
Owner

@gregg-cbs you have the item id.
Before you assign the items from the payload of the event to the items in your app you can use the item id to trivially find the index in both.

@gregg-cbs
Copy link

No no. I went to sortable, they give you the "to" and "from" index, not sure why you want me to do a find on two different datasets when you know the indexes?

How many developers have to spend time struggling to get the indexes, reading the docs, coming to github, realizing they cant and then having to write the same find code over and over again. The amount of energy expended because you think a find is "trivial" is a lot... vs you just adding the "to" and "from" indexes to the detail because you should have them.

Sortable you do:

{
  onEnd: async function (evt) {
    await on_sort(evt.oldIndex, evt.newIndex)
  },
}

@isaacHagoel
Copy link
Owner

isaacHagoel commented Dec 17, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants