最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQueryUI sortable : Allow sorting only to second list but not back to first - Stack Overflow

programmeradmin0浏览0评论

I have two lists I want to use Jquery UI sortable on. The way it is supposed to work is that list One contains a selection of items some of may be dragged to list 2. However sorting within list 1 or dragging back from list 2 to list 1 should not be allowed, finally sorting within list 2 is allowed.

The lists are like this

<ul class="sortable" id = "list1">
    <li> Item 1 </li>
    <li> Item 2 </li>
    <li> Item 3 </li>
    <li> Item 4 </li>
</ul>

<ul class="sortable" id = "list2">
    <li> Item 1 </li>
    <li> Item 2 </li>
    <li> Item 3 </li>
    <li> Item 4 </li>
</ul>

My current sortable call looks like this

$('#list1, #list2').sortable({
    helper: "clone",
    placeholder: "selected-option",
    forcePlaceholderSize: true,
    dropOnEmpty: true,
    connectWith: '.sortable',
    tolerance: "pointer",
    revert: true,
    cursor: "move",
    receive: function (event, ui) {
        // existing logic

    },
    update: function (event, ui) {
        // existing logic
    }
});

I know that I will have to manipulate the stop, receive functions on the sortable call to achieve this, but am not able figure out how to ..

I have two lists I want to use Jquery UI sortable on. The way it is supposed to work is that list One contains a selection of items some of may be dragged to list 2. However sorting within list 1 or dragging back from list 2 to list 1 should not be allowed, finally sorting within list 2 is allowed.

The lists are like this

<ul class="sortable" id = "list1">
    <li> Item 1 </li>
    <li> Item 2 </li>
    <li> Item 3 </li>
    <li> Item 4 </li>
</ul>

<ul class="sortable" id = "list2">
    <li> Item 1 </li>
    <li> Item 2 </li>
    <li> Item 3 </li>
    <li> Item 4 </li>
</ul>

My current sortable call looks like this

$('#list1, #list2').sortable({
    helper: "clone",
    placeholder: "selected-option",
    forcePlaceholderSize: true,
    dropOnEmpty: true,
    connectWith: '.sortable',
    tolerance: "pointer",
    revert: true,
    cursor: "move",
    receive: function (event, ui) {
        // existing logic

    },
    update: function (event, ui) {
        // existing logic
    }
});

I know that I will have to manipulate the stop, receive functions on the sortable call to achieve this, but am not able figure out how to ..

Share Improve this question edited Oct 29, 2013 at 13:45 Manquer asked Oct 29, 2013 at 13:30 ManquerManquer 7,6478 gold badges45 silver badges71 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7
$('#list1, #list2').sortable({
  helper: "clone",
  placeholder: "selected-option",
  forcePlaceholderSize: true,
  dropOnEmpty: true,
  connectWith: '.sortable',
  tolerance: "pointer",
  revert: true,
  cursor: "move",
  beforeStop: function (event, ui) {
    if($(ui.helper).parent().attr('id') === 'list1' && $(ui.placeholder).parent().attr('id') === 'list1')
       return false;
    else if($(ui.helper).parent().attr('id') === 'list2' && $(ui.placeholder).parent().attr('id') === 'list1')
        return false;
  }
});

http://jsfiddle/py7FN/

发布评论

评论列表(0)

  1. 暂无评论