[zTree] Limit Drag and Drop
Forge component by Eduardo Luís


How to limit Drag and Drop to only work at level 0 of the tree? The other levels are not possible to carry out the drag and drop.


I have this code implemented in ztreeSettingsCallback.ztreeSettingsCallback.beforeDrop

In which it limits the user to drag and drop to other nodes..

But the way it is implemented I can do the drag and drop. Like for example:


What I want to do is to limit Drag and Drop only to the root node or level 0.


//insert in ztreeSettingsCallback.ztreeSettingsCallback.beforeDrag

"function (treeId, treeNodes) {

    for (var y=0,l=treeNodes.length; y<l; y++) {
        var treeNode = treeNodes[y];
        var extraOptions = treeNode.extra.split(',');
        for (i=0;i<extraOptions.length;i++) {
            var option = extraOptions[i].split(':');

            if (option[0] == 'drag') {
                if (option[1] == 'false') return false;
                    else if (treeNode.parentTId) {
                    var parentNodeExtraOptions = getParentNode().extra.split(',');
                    for (x=0;x<parentNodeExtraOptions.length;x++) {
                        var poption = parentNodeExtraOptions[x].split(':');
                        if (poption[0] == 'childDrag') {
                            if (poption[1] == 'false') return false;
    return true;
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.