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. Image for the cookie policy date

the order of node and connection creation

Hi.

I want to add two connected connectors when I drag and drop a node from the palette.
 While it is possible to add them manually using "add" in the drop event, the problem is that the node is created after the drop event (when the connection is created), so there is no actual connection.

Is there an API or Method available to solve this?

Alternatively, are there any other events that can be used to solve this (such as "nodeCreated")?





1 Reply

SJ Sivaranjith Jeyabalan Syncfusion Team April 4, 2023 08:15 AM UTC

Hi,

We have achieved your requirement using collectionChange event. When we drag and drop a node from the palette to the diagram, the collectionChange event will be triggered. In this event, we connect a node with two connectors as per your requirement. Please find the sample and code example below.

Code example:

collectionChange: (args) =>{

        if(args.state === 'Changed'){

          if(args.element.inEdges !== undefined){

            let connectors = [

              {

                id:'c1'+randomId(),targetPoint:{x:100,y:100},sourceID:args.element.id,

                sourcePortID:args.element.ports[0].id,type:'Orthogonal',annotations:[{content:'Yes'}]

              },

              {

                id:'c2'+randomId(),targetPoint:{x:100,y:100},sourceID:args.element.id,

                sourcePortID:args.element.ports[2].id,type:'Orthogonal',annotations:[{content:'No'}]

              }

            ];

            diagramInstance.add(connectors[0]);

            diagramInstance.add(connectors[1]);

          }

        }

      },


Regards,

Sivaranjith


Attachment: collectionChangeaddConnector_229b3ec0.zip

Loader.
Live Chat Icon For mobile
Up arrow icon