Diagram Selection not working in some cases

I am trying to do a selection in the graph when the graph component (angular) first loads. Just for some context, there is a graph & a table, and when there is new data, the graph reloads with the new data, hence we need to provide new data for the selection to keep it in-sync with the table.

For this, I have used diagram.select method, and I call this method. The issue is that, it doesn’t work for the very first time, but works at later times when the event is manually triggered by the user. I suspected that the issue might be caused by the diagram being initialised later on, but the method being called first, which meant that the diagram never existed in the first place, hence the method would have definitely failed, or did nothing.

To check this, I added some logs, and I learnt that the diagram was initialised before. Now, I went through the transaction docs, didn’t really understand the significance of the boolean returned by commitTransaction method, but what I found was the value returned was true for selection events manually triggered by the user (which worked), and also true for the selection event on initialisation (which failed). So, I am not really sure what is happening wrong here, and how to fix this in the first place.

The Diagram might have been initialized, but its model may not have been at the time when you called Diagram.select. Have you checked that the argument passed to that method is the Node that you wanted to select? How are you choosing that Node to be selected? If you are calling Diagram.findNodeForKey or Diagram.findNodeForData, it might be returning null because the model data haven’t been loaded yet.

I was using Diagram.findNodeForKey. Just checked, you are indeed right, it is returning null. How can this be solved though?

You have to wait until the model data exists for the diagram.

I suppose you could implement an “InitialLayoutCompleted” DiagramEvent listener and then find the desired Node and then call Diagram.select.