How to Prevent Child Nodes from Other Parents in JavaScript TreeView?
This article explains how to prevent child nodes from other parents in JavaScript TreeView. The following steps are used to prevent a child node from being dropped into another parent node in the JavaScript TreeView control.
Step 1: IImplement the TreeView control using our Getting Started documentation.
Step 2 : To prevent a child node 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;
}
}
Refer to the working sample for additional details and implementation: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
We 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 learn about its other groundbreaking feature representations and documentation, as well as how to quickly get started with 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, BoldDesk Support, or feedback portal. We are always happy to assist you!