Category / Section
Establish connection when a node is dropped on a connector
1 min read
Establish connection when a node is dropped on a connector:
You can use the diagram client side API Event “drop” to establish the connection when node is dropped over the connector.
The following code illustrates how to establish the connection when node is dropped over the connector.
[JS]
$("#DiagramContent").ejDiagram({ drop: drop, connectors: [ { name: "Link1", segments: [{ type: "orthogonal" }], sourcePoint: { x: 0, y: 0 }, targetPoint: { x: 40, y: 40 }, targetDecorator: { shape: "arrow" }, lineWidth: 2, //enable Allow drop on the connector. constraints: ej.datavisualization.Diagram.ConnectorConstraints.Default | ej.datavisualization.Diagram.ConnectorConstraints.AllowDrop, } ] }) function drop(args) { var diagram = $("#DiagramContent").ejDiagram("instance"); if (args.target.type === "connector") { //set the node as targetnode if connector already has source node. if (args.target.sourceNode) { diagram.updateConnector(args.target.name, { targetNode: args.element.name }); } //set the node as sourcenode if connector already has target node. else if (args.target.targetNode) { diagram.updateConnector(args.target.name, { sourceNode: args.element.name }); } //set the node as source/target node if connector dont have both source/target node. else if (!(args.target.sourceNode && args.target.targetNode)) { diagram.updateConnector(args.target.name, { sourceNode: args.element.name }); } } }