Search code examples
jquerylistdrag-and-dropduplicatesjquery-ui-sortable

How do I duplicate item when using jquery sortable?


I am using this method http://jqueryui.com/demos/sortable/#connect-lists to connect two lists that i have. I want to be able to drag from list A to list B but when the item is dropped, i need to keep the original one still in list A. I checked the options and events but I believe there is nothing like that. Any approaches?


Solution

  • For a beginning, have a look at this, and read @Erez answer, too.

    $(function () {
        $("#sortable1").sortable({
            connectWith: ".connectedSortable",
            remove: function (event, ui) {
                ui.item.clone().appendTo('#sortable2');
                $(this).sortable('cancel');
            }
        }).disableSelection();
    
        $("#sortable2").sortable({
            connectWith: ".connectedSortable"
        }).disableSelection();
    });