This project is read-only.

Revert sorting after dragEnd

Aug 16, 2011 at 4:34 PM

Imagine that we have the following scenario:

  1. A drag-sort list that when the dragEnd event fires the current order of the list is persisted in a database.
  2. The commit in the database failed
  3. The last drop must be undone.

How to achieve this?

 

Sep 30, 2011 at 8:34 AM

What you can do is save the existing order on page load:

var list1order = $("#list1 li").toArray();
var list2order = $("#list2 li").toArray();
And then in your dragEnd function you can restore the order like so:
var list1 = $("#list1"), list2 = $("#list2");
$(list1order).each(function() { $(this).appendTo(list1); });
$(list2order).each(function() { $(this).appendTo(list2); });