Fix issue with drag and drop index positioning#1
Open
jfrei wants to merge 2 commits intoSortableJS:masterfrom
Open
Fix issue with drag and drop index positioning#1jfrei wants to merge 2 commits intoSortableJS:masterfrom
jfrei wants to merge 2 commits intoSortableJS:masterfrom
Conversation
- 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).
|
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 } |
Author
|
I've confirmed the code you've pasted above works and it looks better than what I've done 👍 |
Fix issue with newIndex always being 0
|
Yes! Been having the same problem and this fixed it, thank you. Can this please be merged into the master? |
|
Yes, please! Merge it. It solved my last problem with knockout-sortable. |
|
While this works for moving in the same collection, I found that it always needs a +1 when moving from one collection to another. The following worked for me: if (e.item.previousElementSibling) {
newIndex = to().indexOf(ko.dataFor(e.item.previousElementSibling));
newIndex += (from === to && newIndex > originalIndex ? 0 : 1);
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Has not been tested with dragging/dropping with more than one collection.