Show / Hide Table of Contents

Drag and Drop

enableDragDrop

Enabling Drag and drop you can move a node over another to change its parent.

 
    var chart = new OrgChart(document.getElementById("tree"), {
        enableDragDrop: true,   
        ...
    });

In the example bellow drag and drop one of the nodes to see how it works


Drag and Drop Events

If you want to conditionally cancel drag&drop operation add drop event handler
 
    var chart = new OrgChart(document.getElementById("tree"), {
        ...
    });

    chart.on('drop', function (sender, draggedNodeId, droppedNodeId) {
        if (draggedNodeId == 1){
            return false;
        }

        if (droppedNodeId == 4){
            return false;
        }
    });

    chart.load([
        { id: 0 },
        { id: 1, pid: 0 },
        { id: 2, pid: 0 }
    ])

Movable

Using the movable option, you can move a node to change its position in the tree without changing the data structure. You have 3 options:

            var chart = new OrgChart(document.getElementById("tree"), {
                movable: OrgChart.movable.node, // moves the node
                // movable: OrgChart.movable.tree, // moves a node with the tree below
                // movable: OrgChart.movable.detachTree, // detaches the tree
                ...
            });
        
You can test the functionality in this example: