dynamically enable/disable jquery sortable item

前端 未结 5 1329
南旧
南旧 2021-02-07 15:31

I have table rows that are sortable depending on whether certain radio buttons are checked or not. The sortables are initialized on document.ready as follows:

5条回答
  •  孤城傲影
    2021-02-07 15:50

    I know this is old, but had a similar problem. I had my sortable items in groupings. I wanted certain groups to be sortable anywhere and some to only be sortable to a subsection of groups.

    Items from noSort can sort anywhere. Items from canSort can only sort into other canSort blocks.

    $("#sortBlock").sortable({
        items: "> div.itemBlock > .item"   // this makes sure only the sub items will be sortable
    });
    

    Then setting this rule after the init seemed to do the trick.

    $("#sortBlock").sortable( "option", "items", "> div:not(#noSort) > .item");
    

    Was trying to do it dynamically in the start/stop events, but this did the trick, not sure "why", so test well.

提交回复
热议问题