javascript - Sortable - Excluded items still affect index -


i have sortable set this:

$('.sortable').sortable({     items: '> *:not(.nosort)',     axis: 'y',      stop: function (event, ui) {         var index = ui.item.index();         // index     } }); 

i want ignore elements nosort class sortable.

this works good; however, index seems include elements in sortable, not can sorted, can't used need.

is there easy way avoid this?


here's jsfiddle of example sortable.

(note: subtracting 1 index not option, because number , position of excluded elements can vary)

get collection of .sortable children , find index, using .index(), based on that...

you can making following changes:

$(document).ready(function () {     $('.sortable').sortable({         items: '> *:not(.nosort)',         axis: 'y',          stop: function (event, ui) {              // obtain index of moved item             var index = $(this).children(':not(.nosort)').index(ui.item);              $('#index').text(index);          }     }).disableselection(); }); 

demo: http://jsfiddle.net/dirtyd77/yy9hw/3/


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -