Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Working Solution</h2> <p><strong>tl;dr</strong>: <a href="http://jsfiddle.net/hQnWG/614/" rel="noreferrer">Refer to this Fiddle for a working answer</a>.</p> <hr> <p>I looked everywhere for a solution to the issue of <strong>dragging multiple selected items from a sortable into a connected sortable</strong>, and these answers were the best I could find.</p> <p><em>However...</em></p> <p>The accepted answer is buggy, and <strong><a href="https://stackoverflow.com/a/11528315/873263">@Shanimal's answer</a> is close</strong>, but not quite complete. I took @Shanimal's code and built on it.</p> <p>I fixed:</p> <ul> <li>the <a href="https://stackoverflow.com/questions/3774755/jquery-sortable-select-and-drag-multiple-list-items#comment16192416_11528315">disappearing list item bug that @Ryan mentioned</a>,</li> <li>cleaned up the syntax errors in the HTML (missing closing tags &amp; nested <code>&lt;li/&gt;</code>s).</li> </ul> <p>I added:</p> <ul> <li>Proper <kbd>Ctrl + click</kbd> (or <kbd>Cmd + click</kbd> if on a mac) support for selecting multiple items. Clicking <em>without</em> the <kbd>Ctrl</kbd> key held down will cause that item selected, and other items in the same list to be <em>deselected</em>. This is the same click behavior as the <a href="http://api.jqueryui.com/selectable/" rel="noreferrer">jQuery UI <code>Selectable()</code> widget</a>, the difference being that <a href="http://api.jqueryui.com/selectable/" rel="noreferrer"><code>Selectable()</code></a> has a marquee on mousedrag.</li> </ul> <p><a href="http://jsfiddle.net/hQnWG/614/" rel="noreferrer">Fiddle</a></p> <p><strong>HTML:</strong></p> <pre><code>&lt;ul&gt; &lt;li&gt;One&lt;/li&gt; &lt;li&gt;Two&lt;/li&gt; &lt;li&gt;Three&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;Four&lt;/li&gt; &lt;li&gt;Five&lt;/li&gt; &lt;li&gt;Six&lt;/li&gt; &lt;/ul&gt; </code></pre> <p><strong>JavaScript (with jQuery and jQuery UI):</strong></p> <pre><code>$("ul").on('click', 'li', function (e) { if (e.ctrlKey || e.metaKey) { $(this).toggleClass("selected"); } else { $(this).addClass("selected").siblings().removeClass('selected'); } }).sortable({ connectWith: "ul", delay: 150, //Needed to prevent accidental drag when trying to select revert: 0, helper: function (e, item) { var helper = $('&lt;li/&gt;'); if (!item.hasClass('selected')) { item.addClass('selected').siblings().removeClass('selected'); } var elements = item.parent().children('.selected').clone(); item.data('multidrag', elements).siblings('.selected').remove(); return helper.append(elements); }, stop: function (e, info) { info.item.after(info.item.data('multidrag')).remove(); } }); </code></pre> <p><strong>NOTE:</strong></p> <p><em>Since I posted this, I implemented something simmilar - connecting draggable list items to a sortable, with multi-select capability. It is set up almost exactly the same, since jQuery UI widgets are so similar. One UI tip is to make sure you have the <code>delay</code> parameter set for the draggables or selectables, so you can click to select multiple items without initiating a drag. Then you construct a helper that <strong>looks</strong> like all the selected elements put together (make a new element, clone the selected items, and append them), but <strong>make sure</strong> to leave the original item intact (otherwise it screws up the functionality - I cannot say exactly why, but it involves a lot of frustrating DOM Exceptions).</em></p> <p><em>I also added <kbd>Shift + Click</kbd> functionality, so that it functions more like native desktop applications. I might have to start a blog so I can expound on this in greater detail :-)</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload