rniemeyer / knockout-sortable

A Knockout.js binding to connect observableArrays with jQuery UI sortable functionality
MIT License
547 stars 128 forks source link

How do I copy items from one list to another rather than move them? #69

Closed iGrog closed 10 years ago

iGrog commented 11 years ago

How can I keep the original where its at (without re-appending it to the column) and have the clone move to the desired location?

rniemeyer commented 11 years ago

@iGrog - you can use the beforeMove callback to help with this scenario. If you set arg.cancelDrop to true, then it will not actually move it. Then, you can create a clone and add it to the target list. Something like:

    self.myDropCallback = function (arg) {
        arg.targetParent.splice(arg.targetIndex, 0, new Task(arg.item.name()));

        arg.cancelDrop = true;
    };

Here is a sample: http://jsfiddle.net/rniemeyer/UcCTg/

iGrog commented 11 years ago

Thank you, it helped.

iGrog commented 11 years ago

Hm, but afterMove does not fire on target list. How can I e.g. automatically save list after adding cloned item from source list?

rniemeyer commented 11 years ago

@iGrog - the arg passed to afterMove has access to both the sourceParent as well as the targetParent, so you can perform operations on either in that callback.