rmap
rmap

Reputation: 65

JQuery UI sortables display sort order

I cannot find in the JQUI documentation how to display the sort order. What I want to do is display the sort order i.e. 1,2,3, 4, etc as a visual reference for a user. The sort order obviously updates on a sort, just not sure how to find/get the sort order - Oh I'm not sorting <li>'s

Upvotes: 1

Views: 942

Answers (2)

Martin Lisowski
Martin Lisowski

Reputation: 687

You can use the toArray method of sortables: https://api.jqueryui.com/sortable/#method-toArray

Assuming this is your sortable, you can use the following code to retrieve an array of DOM IDs of the sortable's items in sort order:

var arrayOfIds = $(this).sortable("toArray")

Use it in the Stop event handler to update a display, like Andrew suggested. Check the linked documentation if you want to retrieve another attribute rather than the ID.

Upvotes: 0

Andrew Orsich
Andrew Orsich

Reputation: 53695

You can do it youself, just recalculate order on each stop event of sortable element:

... 
 stop: function (event, ui) {
                setOrder();
            },
...
function setOrder() {
 $("#liContainerId").each(function (index,li) {
  // set display order here
});
}

Upvotes: 1

Related Questions