I want the value of the list item to be the index of the sorted position during the sorting event.
This value should be updated automatically during the sort change event.
<script type="text/javascript"> $(function() { $('#sortable').sortable({ start : function(event, ui) { var start_pos = ui.item.index(); ui.item.data('start_pos', start_pos); }, change : function(event, ui) { var start_pos = ui.item.data('start_pos'); var index = ui.placeholder.index(); if (start_pos < index) { $('#sortable li:nth-child(' + index + ')').html(index-2); } else { $('#sortable li:eq(' + (index + 1) + ')').html(index + 1); } }, update : function(event, ui) { var index = ui.item.index(); $('#sortable li:nth-child(' + (index + 1) + ')').html(index); }, axis : 'y' }); }); </script>
I created a fiddle http://jsfiddle.net/jagan2explore/4mcpq/
to explain my requirement.
If I move the 1st element to the 5th position, all other values ββof the elements are updated correctly, If I move the 5th and 1st values, respectively.
Suppose if I move a list item from 1 to 5 and from 5 to 2 without leaving (during a single sort event) the values ββare not updated accordingly.
Am I missing something ??
Any help would be greatly appreciated. thanks in advance
source share