BeToChe
BeToChe

Reputation: 37

How to use jquery ui sortable?

I have a CMS and in my CMS I need to sort my menu by jquery sortable!

What is the result of sorting, I mean when I drag and drop an element by sortable what is the result of sorting? does jquery sortable give me a number of index?

for example:

when I drag an Item that is at the first in the menu, and put it at the end of the menu how to get index of the item at it's new position?

Upvotes: 4

Views: 1730

Answers (1)

King King
King King

Reputation: 63377

You can handle the event sortstop (which can be done via the option stop), at this time the items have already had new order, you can access to the ui.item to get the dropped item and use .index() method to know its index in the collection of items (having the same parent):

$('ul').sortable({
  stop: function(e,ui){
    //show the index
    alert(ui.item.index());
  }
});

Demo.

Upvotes: 6

Related Questions