Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Sortable - Keep it in original list

Does anyone know if jQuery UI's Sortable has built-in functionality to keep the original dropped item in it's original list?

For example, you have two lists (one 'source' and one 'group'). I'd like to select from the source and drop into the group, but keep the item in the source.

Make sense?

Thank you!

like image 269
dzm Avatar asked Sep 08 '10 14:09

dzm


1 Answers

You can see my solution in action on jsfiddle. I simply amended this jQuery draggable/droppable interaction to suit your needs.

HTML

<div class="demo">
    <h2>List 1</h2>
    <ul>
        <li class="draggable ui-state-highlight">Drag me down</li>
        <li class="draggable ui-state-highlight">Drag me down</li>
    </ul>
    <h2>List 2</h2>
    <ul id="sortable">
        <li class="ui-state-default">Item 1</li>
        <li class="ui-state-default">Item 2</li>
        <li class="ui-state-default">Item 3</li>
        <li class="ui-state-default">Item 4</li>
        <li class="ui-state-default">Item 5</li>
    </ul>
</div>

jQuery

$(function() {
    $("#sortable").sortable({
        revert: true
    });
    $(".draggable").draggable({
        connectToSortable: "#sortable",
        helper: "clone",
        revert: "invalid"
    });
    $("ul, li").disableSelection();
});

CSS

.demo ul { list-style-type: none; margin: 0; padding: 0; margin-bottom: 20px; }
.demo li { margin: 5px; padding: 5px; width: 150px; border: 1px solid black; }
like image 94
David Spence Avatar answered Oct 11 '22 16:10

David Spence