0

I'm attempting to create a case priority list for a client, and will be using Jquery UI for the drag and drop feature.

The problem I am sitting with at the moment is finding out the new Index of the list item once it has been moved. I am hoping one of you has encountered this before or knows how I can get this? I am really struggling to find it.

I have tried lots of SO thread which say I should use .index(), but i cant seem to get it working. Please see my attempt in this FIDDLE

 $(document).ready(function () {

       var Items = $("#SortMe li");

     $('#SortMe').sortable({
         disabled: false,
         axis: 'y',
         forceHelperSize: true,
         update: function () {
             var Newpos = $("li").index();
             alert("You moved item to position " + Newpos);

         }
     }).disableSelection();
 });

Once the list item has been dropped, I would like to know its new position / index so I can use this in SQL later on in the process.

Thanks so much, Mike

Community
  • 1
  • 1
Fizor
  • 1,480
  • 1
  • 16
  • 31

1 Answers1

1

Basically you're doing alright, except you're targeting the wrong element. You should instead check ui.item for the current dragged element.

Demo: http://jsfiddle.net/fKvv3/17/

jAndy
  • 231,737
  • 57
  • 305
  • 359