How to Perform Drag and Drop Operation in OrgChart Vue Diagram?
This article explains how to perform a drag-and-drop operation in the OrgChart Vue 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 Vue Diagram.
Additionally, the AllowDrop constraints need to be enabled to display a highlighter when dragging a node and hovering the mouse over another node.
Please refer to the provided code example for more information.
<template>
<ejs-diagram
style="display: block"
ref="diagramObject"
id="diagram"
:width="width"
:height="height"
:getNodeDefaults="getNodeDefaults"
:getConnectorDefaults="getConnectorDefaults"
:drop="drop"
:created="created"
:layout="layout"
:dataSourceSettings="dataSourceSettings"
></ejs-diagram>
</template>
// Drop event
drop: (args) => {
setTimeout(() => {
let diagram = this.$refs.diagramObject.ej2Instances;
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 in the palette and drop it onto a node in the diagram
if (args.target.id !== args.element.id) {
diagram.add({
id: 'connector' + randomId(),
sourceID: args.target.id,
targetID: args.element.id,
});
}
}
// To update the layout
diagram.doLayout();
}
}, 100);
diagram.fitToPage();
},
Refer to the working sample for additional details and implementation: Sample
Conclusion
I hope you enjoyed learning how to perform drag-and-drop operations in OrgChart Vue Diagram.
You can refer to our Vue 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 Vue 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!