Browse Source

Fixed issue with computed foreach's

Fixed how we find correct indexes for items if the sortable is
bound to a filtered collection.
pull/497/head^2
srosengren 10 years ago
parent
commit
a6f86320ce
  1. 10
      knockout-sortable.js

10
knockout-sortable.js

@ -67,7 +67,13 @@
//Unwrapping this allows us to manipulate the actual array //Unwrapping this allows us to manipulate the actual array
var fromArray = from(), var fromArray = from(),
//It's not certain that the items actual index is the same as the index reported by sortable due to filtering etc. //It's not certain that the items actual index is the same as the index reported by sortable due to filtering etc.
originalIndex = fromArray.indexOf(itemVM); originalIndex = fromArray.indexOf(itemVM),
newIndex = e.newIndex;
if (e.item.previousElementSibling)
newIndex = fromArray.indexOf(ko.dataFor(e.item.previousElementSibling));
if (originalIndex > newIndex)
newIndex = newIndex + 1;
//Remove sortables "unbound" element //Remove sortables "unbound" element
e.item.parentNode.removeChild(e.item); e.item.parentNode.removeChild(e.item);
@ -85,7 +91,7 @@
from.valueHasMutated(); from.valueHasMutated();
} }
//Insert the item on its new position //Insert the item on its new position
to().splice(e.newIndex, 0, itemVM); to().splice(newIndex, 0, itemVM);
//Make sure to tell knockout that we've modified the actual array. //Make sure to tell knockout that we've modified the actual array.
to.valueHasMutated(); to.valueHasMutated();
}; };

Loading…
Cancel
Save