How to drag and drop a node from treeview to diagram
This article explains how to drag and drop a node from the TreeView to the diagram.
In the diagram, you can drag and drop a node from the treeview to the diagram. When you drag and drop a node from the treeview to the diagram, the treeview’s nodeDragStop event gets triggered. In the event, using the offsetX and offsetY arguments, you can find the node's dropped position. In the nodeDragStop event, create a new node and set the event arguments' offsetX and offsetY positions to the node's offsetX and offsetY positions. After creating a new node, add the node to the diagram using the diagram’s add public API method, so that the node gets dropped at the mouse position. Please refer to the following code example and sample to learn how to drag and drop a node from the treeview to the diagram.
public onDragStop(args: any): void {
let targetEle: any = closest(args.target, '.e-droppable');
targetEle = targetEle ? targetEle : args.target;
// Check a target as a diagram.
if (targetEle.classList.contains("e-diagram")) {
let data: any = args.draggedNodeData.text;
//Add a node at runtime.
this.diagram.add({
id: data + randomId(), width: 100, height: 100, offsetX: args.event.offsetX, offsetY: args.event.offsetY,
annotations: [{ content: data, }]
});
args.clonedNode.remove();
}
}
Refer to the working sample for additional details and implementation: https://stackblitz.com/edit/angular-ydjhjz-3vq5bk
Conclusion
We hope you enjoyed learning about how to drag and drop a node from treeview to diagram.
You can refer to our JavaScript Diagram 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 Diagram 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!