views:

20

answers:

1

I am working with jQuery UI Sortable plugin, and applying it to a table. How would I trigger a function when dropping whatever element I am dragging? Something similar to below:

alert($(this).attr('id'));

Full Solution

For this, you have to set the container id's to something_number (something_1, something_2, etc).

$(function(){
    $('#sortable').sortable({
        placeholder: 'ui-state-highlight',
        update: function(event, ui){
            var order = $('#sortable').sortable('serialize');
            alert(order);
        }
    });
    $("#sortable").disableSelection();
});
+1  A: 

This can be done easily be using stop event. Details are documented here.

Quick example:

$( "#your-id" ).sortable({
   stop: function(event, ui) { 
      alert($(this).attr('id'));
   }
});

You can alternatively give a try to other events like update depending on what are you needs exactly.

Lukasz Dziedzia