Sortable items and subitems in list on jQuery ui sortable

天涯浪子 提交于 2019-12-05 03:35:43

If I understand you correctly you need two sortables - one for the parents and one for the children and then the children should connectWith the parents and you need a tolerance property.

// Sort the parents
$(".sortable").sortable({
    containment: "parent",
    items: "> div",
    handle: ".move",
    tolerance: "pointer",
    cursor: "move",
    opacity: 0.7,
    revert: 300,
    delay: 150,
    dropOnEmpty: true,
    placeholder: "movable-placeholder",
    start: function(e, ui) {
        ui.placeholder.height(ui.helper.outerHeight());
    }
};

// Sort the children
$(".group-items").sortable({
    containment: "parent",
    items: "> div",
    tolerance: "pointer",
    connectWith: '.group-items'
});

See my Fiddle demo.

UPDATE #1

Updated Fiddle demo to only allow children to bind to its parent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!