Event to capture a new node been added to group

I’ve implemented a group node template map, category: MainGroup which is having property mouseDrop: finishDrop.

When I drop a new node inside the MainGroup key:1, how can i get confirmation that a new node was added inside the group and also get the total count of members inside the group.

If your code is adding members to a group, you can execute code then, including counting how many Nodes are in the Group.memberParts.

More generally, you can implement Group | GoJS API. But note that it gets called whenever a node is added, not just when your code adds a node.

In my case after having memberAdded and memberRemoved implemented to group template category: MainGroup, when I load a diagram the memberAdded and memberRemoved gets automatically called.

My loading json diagram.model.nodeDataArray is having a groupnode with category: MainGroup.

I am able perform operations on memberAdded and memberRemoved and save them in my diagram.model.nodeDataArray, but it gets called again once the diagram is reloaded.

example, on my angular project when a member added to group will startTransaction to add a new node and commit and save, everytime I go back and come back to Diagram there are unwanted duplicate nodes added to canvas.

Yes, as I said in the second suggestion, those event handlers get called in all situations.

In the first suggestion, you would control when your code is called.

Is there any way of controlling those Events and preventing them from pre loading? I dont want them to start the transactions everytime it is reloaded. If there is a way of prevent such thing from happening may i get a small example for how to implement?

Set a flag before assigning a new model, clear it in an “InitialLayoutCompleted” DIagramEvent listener.

did something similar for loading layout, not sure how to perform it with new model.

InitialLayoutCompleted: function (e) {
if (
!e.diagram.nodes.all(function (n) {
return n.location.isReal();
})
) {
e.diagram.layoutDiagram(true);
}
},

Create a new flag that is initially false and that you set before assigning a new model, and clear it in an “InitialLayoutCompleted” DiagramEvent listener.

In your Group.memberAdded and memberRemoved event handlers, check that flag and only do what you wanted when that flag is false – i.e. not when loading a model.

Thanks a lot Walter!