Jquery ui sortable drop event

user1942626 picture user1942626 · Jul 21, 2013 · Viewed 40.1k times · Source

I am working with jquery ui sortable. I would like to get the sorting array to pass it to the handling file on drop event.

one funny thing i found.. http://jsfiddle.net/7Ny9h/

$(function() {
    $( "#sortable" ).sortable();
    $( "#sortable" ).disableSelection();

    $( "#sortable li" ).droppable({
        drop: function( ) {
            var order = $("#sortable").sortable("serialize", {key:'order[]'});
            $( "p" ).html( order );
        }
    });
});

Seeing the sample, if I move BOX No.2, the BOX 2 is left out of the array.

Perhaps I need a kind of "dropend" event because it seems that jquery ui drop event doesn't count the dragged and dropped one.

Answer

Ari picture Ari · Dec 9, 2014

You can also use update to detect it.

$( "#sortable" ).sortable({
    update: function( ) {
        // do stuff
    }
});