SortableJS / knockout-sortablejs

A Knockout.js binding to SortableJS.
21 stars 19 forks source link

Sorting problem #12

Open guillome2k opened 6 years ago

guillome2k commented 6 years ago

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

Insinfi commented 5 years ago

I have the same probleme have you found any fix ?

guillome2k commented 5 years ago

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

Insinfi commented 5 years ago

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

guillome2k commented 5 years ago

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

  1. Line 87, added:

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

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

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

  5. 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(); }

Insinfi commented 5 years ago

Ok perfect thanks you saved me a bunch of hours

guillome2k commented 5 years ago

Yw :) success!