Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ui sortable, get sending object

I have a two tables which items can sort/drop between both. In my beforeStop method I am trying to access the sender, the element the item has come form - but I am getting null.

http://api.jqueryui.com/sortable/#event-beforeStop

  $( "tbody" ).sortable({
            connectWith: "tbody",
            distance: 15,
            beforeStop: function(event, ui) {
                 console.log(ui.sender);

the console says

null

How can I get the element which the item has come from?

like image 226
Wizzard Avatar asked Aug 25 '26 02:08

Wizzard


1 Answers

You can keep the source container in a variable on the start event.

jsFiddle Demo

var startElement = null;

$("#sortable").sortable(
    {
        start: function (event, ui) {
            startElement = $(this)
        },
        beforeStop: function(event, ui) {
            console.log(startElement);
        },
        connectWith: "#sortable2"
    }
);
like image 106
Itay Avatar answered Aug 27 '26 18:08

Itay