How to Prevent Child Nodes from Other Parents in JavaScript TreeView?
The following steps used to achieve prevent a child node from being dropped into another parent node in the JavaScript TreeView control.
Step 1 : Implement the TreeView control using our Getting Started documentation.
Step 2 : To prevent a child nodes from being dropped into another parent node, utilize the “nodeDragStop” event and check if the droppedNodeData argument contains the hasChildren field with a value of true. If it does, set “args.cancel” to true to prevent the child node from being dropped into another parent node.
// Render the TreeView with image icons
var treeObj = new ej.navigations.TreeView({
.....
allowDragAndDrop: true,
nodeDragStop: dragStop,
});
treeObj.appendTo('#tree');
function dragStop(args) {
if(args.droppedNodeData != null && args.droppedNodeData.hasChildren){
args.cancel = true;
}
}
Sample : JavaScript-TreeView-PreventDragAndDrop
See Also :
- Drag and drop in EJ2 JavaScript Treeview control
- Restrict the drag and drop for particular tree nodes in EJ2 JavaScript Treeview control
Conclusion
I hope you enjoyed learning how to prevent child nodes from other parents in JavaScript TreeView.
You can refer to our JavaScript TreeView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript TreeView example to understand how to create and manipulate data.For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!