Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the id of sortable element?

I'm using Sortable and got it up and working. But I'm trying to save what is where inside the lists.

Lets say i have 3 lists:

<ul id="top" class="connectedSortable">
<li>elem1</li>
<li>elem2</li>
<li>elem2</li>
</ul>

<ul id="left" class="connectedSortable">
</ul>

<ul id="right" class="connectedSortable">
</ul>

jQuery:

$("#top, #left, #right")
.sortable({
    connectWith: ".connectedSortable",
    stop: function(event, ui)
    {
        alert(this.id); // printing top, left right...
    }
})
.disableSelection();

I've tried to use the stop event inside sortable but it only returns the ul's id of course. So what I want is jQuery to tell me when I've moved elem1 from list1 to list2 (or any elemX of course).

I'm trying to make a homepage that the user could define the layout themselves.

like image 912
Jason94 Avatar asked Mar 09 '11 11:03

Jason94


1 Answers

I think you want to use the receive callback:

http://jsfiddle.net/nzskv/1/

$("#top, #left, #right").sortable({
    connectWith: ".connectedSortable",
    receive: function(event, ui) {
        alert("[" + this.id + "] received [" + ui.item.html() + "] from [" + ui.sender.attr("id") + "]");
    }
}).disableSelection();
like image 149
Adam Ayres Avatar answered Oct 06 '22 02:10

Adam Ayres