Articles in this section
Category / Section

How to Delete Child Nodes in Angular Diagram Layout?

2 mins read

Syncfusion® Angular Diagram provides various Automatic Layout algorithms. In these layouts, nodes are organized with parent-child relationships. When a node is selected and a delete operation is performed, typically only the connectors associated with the node are removed. This is the default behavior, even when using a layout algorithm.

By default, when deleting a parent node, the child nodes are not deleted. Only the connectors related to the parent node are removed, leaving the child nodes in the diagram.

However, if you need to delete the child nodes, we have a solution for it. When deleting a selected node, we can retrieve the outgoing connectors from the node using its outEdges property. With the outEdges property, we can access the connector object and retrieve the child nodes connected to it via the connector’s targetID. Using these IDs, we can remove the child nodes associated with the deleted node.

We have mapped the solution to usehandle delete option and Custom commands Keyboard delete button manually
The following code illustrates how to get child nodes from deleted nodes in Layout:

let deletednode = this.diagram.selectedItems.nodes[0]
let outEdgesColl = (deletednode as any).outEdges;
for (var i = outEdgesColl.length; i >= 0; i--) {
 let targetChild = this.diagram.getObject(outEdgesColl[i]);
 if (targetChild) {
   let child = this.diagram.getObject((targetChild as ConnectorModel).targetID);
   this.diagram.remove(child);
 }
}
this.diagram.remove(); 

You can find a working example of this implementation in the provided sample on StackBlitz.

Sample

Conclusion
I hope you enjoyed learning how to set position for swimlane and its children in Angular Diagram.

You can refer to our Angular 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 Angular 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, Direct-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  to leave a comment
Access denied
Access denied