Articles in this section
Category / Section

How to perform Drag and drop operation in OrgChart in JavaScript Diagram?

2 mins read

How to perform Drag and Drop operation in OrgChart

In the Orgchart sample, we can drag and drop the node onto another node using the drop event which establish the parent/child relationship in JavaScript Diagram. Also we need to enable the AllowDrop constraints which shows the highlighter, when we drag the node and mouse hover on the another node. Please refer to the code example and sample below.

 

JS

 
$("#diagram").ejDiagram({                         
    defaultSettings: {
      //set the default properties of the nodes.
       node: {
      //enable the Allowdrop constraints which shows the highlighter, when we drag the node and mouse hover on the another node.
       constraints: ej.datavisualization.Diagram.NodeConstraints.Default | ej.datavisualization.Diagram.NodeConstraints.AllowDrop,
          },                 
       },
       //define drop event
        drop: drop,           
});
 
 
 
 function drop(args) {
   var diagram = $("#diagram").ejDiagram("instance");
   if (!args.source.cssClass) {
     if (diagram.getObjectType(args.target) == "node") {
        if (args.element) {
           var connector = diagram.findNode(args.element.inEdges[0]);
         }
         if (connector) {
            diagram.updateConnector(connector.name, { sourceNode: args.target.name, targetNode: args.element.name });
          }
          else {
              diagram.add({ name: "connector" + ej.datavisualization.Diagram.Util.randomId(), segments: [{ type: "orthogonal" }], sourceNode: args.target.name, targetNode: args.element.name });
               }
        }
     }
     //update the layout
     diagram.layout();
  }

 

Sample: https://jsplayground.syncfusion.com/mrkleqy1

 

Conclusion

I hope you enjoyed learning about how to perform Drag and drop operations in OrgChart in JavaScript 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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied