)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to perform Drag and drop operation in OrgChart

Platform: jQuery |
Control: ejDiagram |
Published Date: December 15, 2015 |
Last Revised Date: May 30, 2019

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. 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: http://jsplayground.syncfusion.com/mrkleqy1

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon