How to add a group node in the symbol palette at run time
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:
public addButton()
{
let palette2 = [{ id: 'groupPalette', expanded: true, title: 'Group Nodes' }];
this.symbolpalette.addPalettes(palette2);
var nodes = this.diagram.nodes[4];
if (nodes.children) {
for (var i = 0; i < (nodes.children).length; i++) {
var child1 = this.diagram.getObject((nodes.children[i]));
this.symbolpalette.addPaletteItem('groupPalette', child1, true);
this.symbolpalette.dataBind();
};
this.symbolpalette.addPaletteItem('groupPalette', nodes, false);
this.symbolpalette.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.