开发者

jquery ui sortable - containment or cancel for only some items in sortable, only some destinations

开发者 https://www.devze.com 2023-02-15 17:22 出处:网络
Here is the crux of it: I need to disable/contain dragging and dropping between two sortables only for particular items, while allowing those same items to be dragged and dropped within their sortable

Here is the crux of it: I need to disable/contain dragging and dropping between two sortables only for particular items, while allowing those same items to be dragged and dropped within their sortable. I don't see how I can do this with cancel or containment because they either apply to all sorting or all items. Is it possible to only c开发者_如何学Cancel sorting between sortables? or is it possible to only contain certain items?

Here is the background situation: I have two sortables that connect fine using the connectWith option. They represent two columns of a newsletter, and you can add items to each column and drag and drop them between them. However, these items have types and there is a limit to the number of items of each type that you can have in each column. So the problem is that I want to disable dragging items from one column to the other column if the other column has already maxed out on that type of item. I have no problem identifying when an item type is maxed out in a column or identifying which items should or shouldn't be dragged. It's just a matter of triggering the right functionality in jquery ui.


  • DEMO: http://jsbin.com/ipowo5
$(function() {
    $( "#sortable1, #sortable2" ).sortable({
      connectWith: ".connectedSortable",
      receive: function(event, ui) { 
        if ( $(this).find('li').size() == 7 ) {
         $(ui.sender).sortable('cancel');
        }
      }
    });
  });

if #sortable reach 7 items it stop accepting other items

0

精彩评论

暂无评论...
验证码 换一张
取 消