How to Perform Drag and Drop Operation in OrgChart JS Diagram?
In the OrgChart sample, one can create a parent/child relationship by dragging and dropping a node onto another node using the drop event in JavaScript Diagram.
Additionally, the AllowDrop constraints need to be enabled to display a highlighter when dragging the node and hovering the mouse over another node.
Please refer to the provided code example for more information.
drop: function (args) {
setTimeout(() => {
var connector = {};
if (args.element && args.target) {
if (args.element) {
// Get a connector object
connector = diagram.getObject(args.element.inEdges[0]);
}
// This block is executed when we drag any node in the diagram and drop it onto the another node
if (connector) {
// Update connector source and target ID
connector.sourceID = args.target.id;
connector.targetID = args.element.id;
diagram.dataBind();
} else {
// This block is executed when we drag a node from the palette and drop it onto a node in the diagram
if (args.target.id !== args.element.id) {
diagram.add({
id: 'connector' + ej.diagrams.randomId(),
sourceID: args.target.id,
targetID: args.element.id,
});
}
}
// To update an layout
diagram.doLayout();
}
}, 100);
diagram.fitToPage();
},
The following sample illustrate the working of the how drag and drop in OrgChart works
Conclusion
I hope you enjoyed about how to perform drag and drop operation in OrgChart JS Diagram.
You can refer to our JavaScript Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with 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, Direct-Trac, or feedback portal. We are always happy to assist you!