knockout-sortablejs icon indicating copy to clipboard operation
knockout-sortablejs copied to clipboard

Fix issue with drag and drop index positioning

Open jfrei opened this issue 9 years ago • 5 comments

  • Fixes issue with data-bind: sortable element for a non-computed observable array. Dragging an item from a smaller index (eg 0) to a greater index (eg 10) places the element one position after the desired drop position (eg newIndex + 1).

Note: Has not been tested with dragging/dropping with more than one collection.

jfrei avatar Jul 13 '16 16:07 jfrei

Actually, I'm finding that newIndex is always 0 at that point and so the fix isn't working for me, but I'm glad that someone is looking into it.

This seems to work for me, but isn't pretty:

140                 if (e.item.previousElementSibling) {
141                     newIndex = to().indexOf(ko.dataFor(e.item.previousElementSibling));
142                     newIndex += (newIndex > originalIndex ? 0 : 1);
143                 }

NoOutlet avatar Jul 13 '16 16:07 NoOutlet

I've confirmed the code you've pasted above works and it looks better than what I've done :+1: Also, quick thanks for the plugin, saved me lots of time :)

jfrei avatar Jul 14 '16 16:07 jfrei

Yes! Been having the same problem and this fixed it, thank you. Can this please be merged into the master?

matthewnitschke avatar Dec 23 '16 17:12 matthewnitschke

Yes, please! Merge it. It solved my last problem with knockout-sortable.

crystalfp avatar Jan 06 '21 08:01 crystalfp