简体   繁体   English

jQuery多选可拖动/可排序

[英]jQuery Multi-Select Dragable / Sortable

I am working on a drag & drop page which allows a user to pick fields from a source list and drop them in their choice of a destination list. 我在一个拖放页面上工作,该页面允许用户从源列表中选择字段并将其拖放到目标列表中。

While this functionality is working on a high level, I am trying to make the experience a little better by allowing for multiple fields to be selected at the same time and moved. 虽然此功能在较高水平上起作用,但我试图通过允许同时选择和移动多个字段来使体验更好一些。

Sortable: 可排序:

$('#in_available_fields').sortable({
connectWith: '.sortable-list',
placeholder: 'placeholder',
start: function(event, ui) {
  if (!$(ui.item).hasClass("allowPrimary")) {
    $(".primaryPanel").removeClass('panel-primary').addClass("panel-danger");
  }
  if (!$(ui.item).hasClass("allowSecondary")) {
    $(".secondaryPanel").removeClass('panel-primary').addClass("panel-danger");
  }
  if (!$(ui.item).hasClass("allowExport")) {
    $(".exportPanel").removeClass('panel-primary').addClass("panel-danger");
  }
  checkFields()
},
....

Dropzone: 拖放区:

 // Enable dropzone for primary fields
  $('.primaryDropzone').sortable({
    connectWith: '.sortable-list',
    placeholder: 'placeholder',
    receive: function(event, ui) {
      // If we dont allow primary fields here, cancel
      if (!$(ui.item).hasClass("allowPrimary")) {
        $(ui.placeholder).css('display', 'none');
        $(ui.sender).sortable("cancel");
      }
    },
    over: function(event, ui) {
      if (!$(ui.item).hasClass("allowPrimary")) {
        $(ui.placeholder).css('display', 'none');
      } else {
        $(ui.placeholder).css('display', '');
      }
    },
   ....

My thought, to make it clear to users would be to add a checkbox before the label on each field. 我的想法是,要使用户清楚知道将在每个字段的标签前添加一个复选框。 This way they could check multiple at one time and then when they drag them over, it would move all of the selected ones. 这样,他们可以一次检查多个,然后将它们拖到上方时,它将移动所有选定的对象。

Any thoughts on the best way to approach this? 对解决此问题的最佳方法有何想法? I struggled to get this far with the drag and drop and I am a little unsure on how to come up with a multi-select feature for this. 我很难通过拖放操作做到这一点,我不确定如何为此提供多选功能。

Fiddle: https://jsfiddle.net/839rvq2k/ 小提琴: https : //jsfiddle.net/839rvq2k/

You can refer to this fiddle for the multisortable feature of library here 您可以参考这个小提琴图书馆的multisortable特征在这里

Extends jQueryUI sortable to allow selection and sorting of multiple elements https://github.com/shvetsgroup/jquery.multisortable 扩展jQueryUI可排序以允许对多个元素进行选择和排序https://github.com/shvetsgroup/jquery.multisortable

JS: JS:

  $(function(){ $('ul.sortable').multisortable(); });

Html: HTML:

<h2>List 1</h2>
    <ul id="list1" class="sortable">
        <li>Item 11</li>
        <li>Item 12</li>
        <li class="child">Item 12a</li>
        <li class="child">Item 12b</li>
        <li>Item 13</li>
        <li>Item 14</li>
        <li>Item 15</li>
        <li>Item 16</li>
        <li>Item 17</li>
        <li>Item 18</li>
        <li>Item 19</li>
    </ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM