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

Sorting problem

Open guillome2k opened this issue 7 years ago • 6 comments
trafficstars

Hi,

Thanks for this wonderfull binding. Only, the following line makes the sorting go wrong when i sort down:

if (e.item.previousElementSibling) { // Uit want foute sorting
     newIndex = to().indexOf(ko.dataFor(e.item.previousElementSibling)) + 1;
}

http://jsfiddle.net/wgv76t25/36

guillome2k avatar Jul 12 '18 12:07 guillome2k

I have the same probleme have you found any fix ?

Insinfi avatar Aug 21 '18 13:08 Insinfi

I made a couple of changes for my project and is working very nice

guillome2k avatar Aug 21 '18 13:08 guillome2k

May I ask you to share what you have done please ?

Insinfi avatar Aug 21 '18 14:08 Insinfi

Ok, i dont remember exactly what was for my project specific or not.

  1. Line 87, added:
if (options.onCreate) { 
        	options.onCreate(sortableElement);
        }
  1. Line 142, changed: if (e.item.previousElementSibling && from !== to) {

  2. Line 156, changed: if (!ko.isComputed(from)) { from.valueHasMutated(); }

  3. Line 162, changed: if (!ko.isComputed(from)) { from.valueHasMutated(); }

  4. Line 163-167 changed: if (from === to) { // Aanpassing WTG // Insert the item on its new position to().splice(newIndex, 0, itemVM); // Make sure to tell knockout that we've modified the actual array. to.valueHasMutated(); }

guillome2k avatar Aug 21 '18 14:08 guillome2k

Ok perfect thanks you saved me a bunch of hours

Insinfi avatar Aug 21 '18 14:08 Insinfi

Yw :) success!

guillome2k avatar Aug 21 '18 14:08 guillome2k