sortablejs-vue3
sortablejs-vue3 copied to clipboard
Undo a sort action?
I'm using this library for sorting a list, and I'm saving the sort order server-side. I do this by listening to the end event, looping through items between event.oldIndex and event.newIndex, and performing an upsert to the database setting the order field to the new index.
This works, but what do I do if there's a network error? How can I reorder the list back to the way it was before an element was moved? I'm kind of stumped because this version of Sortable doesn't have a value/modelValue property, only a list property. And this list's order seems to be stored internally within this Sortable component. Updating the list value does nothing. I assume it's read once at initialization, and then the component handles the list internally from there. That's fine, but how can I manually change the order of elements if I want to, such as in this case?
Would something as described here work? Otherwise I'm open to suggestions on how an API could look for your use case.