Search code examples
jqueryjquery-uijquery-ui-sortableundo-redo

How to undo/redo a sortable action in jqueryui?


I have a sortable list(jquery ui), could you advise if it is possible to implement 'undo/redo' base on sortable?

Imagine that, a item is dragged to a new placeholder, then I click "undo" button and the item will move to its original position. If I click "redo" button and the item will move to that new placeholder.

Maybe someone knows how to do this or maybe something else. thanks in advance.


Solution

  • After each move (on update), you could store the serialized (or use toArray) order in a variable, and then use that to re-order your items in the event of an "undo." In fact, you could push the serialized data onto an array, giving you the ability to "undo" several times.