From 5bbabe7c0855b8965a1859e7fd6c99de8c50511b Mon Sep 17 00:00:00 2001 From: 4imble Date: Wed, 14 Oct 2015 08:46:37 +0100 Subject: [PATCH] Fix to knockout sorting when dragging item index 1 to 0. The items would not swap positions when you dragged item with index 1 to the top of the stack at index 0. --- knockout-sortable.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/knockout-sortable.js b/knockout-sortable.js index fcf7d66..0288197 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -84,9 +84,11 @@ newIndex = e.newIndex; if (e.item.previousElementSibling) + { newIndex = fromArray.indexOf(ko.dataFor(e.item.previousElementSibling)); - if (originalIndex > newIndex) - newIndex = newIndex + 1; + if (originalIndex > newIndex) + newIndex = newIndex + 1; + } //Remove sortables "unbound" element e.item.parentNode.removeChild(e.item);