how do i track what position an element is when its position in the list/sortable changes?
A:
From the jQuery UI docs:
All callbacks receive two arguments: The original browser event and a prepared ui object, view below for a documentation of this object (if you name your second argument 'ui'):
ui.helper - the current helper element (most often a clone of the item)
**ui.position - current position of the helper**
ui.offset - current absolute position of the helper
ui.item - the current dragged element
ui.placeholder - the placeholder (if you defined one)
ui.sender - the sortable where the item comes from
(only exists if you move from one connected list to another)
MiG
2010-06-05 08:09:18
+2
A:
You can use the ui
object provided to the events, specifically you want the stop
event, the ui.item
property and .index()
, like this:
$("#sortable").sortable({
stop: function(event, ui) {
alert("New position: " + ui.item.index());
}
});
You can see a working demo here, remember the .index()
value is zero-based, so you may want to +1 for display purposes.
Nick Craver
2010-06-06 13:31:41