Articles in this section
Category / Section

How to add group node in symbol palette at run time in JavaScript Diagram?

2 mins read

Group is used to cluster multiple nodes and connectors into a single element in a diagram. The child elements inside a group can be edited individually. Moreover, a group node can be seamlessly integrated into the symbol palette, providing users with the flexibility to drag and drop it onto the canvas multiple times. The following code demonstrates how to dynamically add a group node, along with a regular node, to the symbol palette at runtime using JavaScript Diagram:

document.getElementById('add').onclick = function () {
 let palette2 = [{ id: 'groupPalette', expanded: true, title: 'Group Nodes' }];
     palette.addPalettes(palette2);
     var nodes = diagram.nodes[4];
     if (nodes.children) {
         for (var i = 0; i < (nodes.children).length; i++) {
             var child1 = diagram.getObject((nodes.children[i]));
             palette.addPaletteItem('groupPalette', child1, true);
             palette.dataBind();
         };
     }
     palette.addPaletteItem('groupPalette', nodes, false);
     palette.dataBind();
 
};

In this code snippet, a new palette titled ‘Group Nodes’ is dynamically added to the symbol palette when a button is clicked. The group node and its children are then added as palette items using the addPaletteItem method. This method considers whether the item is a group node or a child, allowing for the appropriate addition to the palette. Finally, the dataBind method is invoked to apply any pending property changes immediately to the component.

For a hands-on demonstration, refer to the sample illustrating how to add a group node to the symbol palette at runtime with a button click.

Conclusion
I hope you enjoyed learning about how to add a group node in the symbol palette at run time 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 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