Retain the expand/collapse state after saving

In layeredDiGraph Layout, I’m using TreeExpanderButton to expand/collapse the nodes.

If the node is collapsed, I want to display the count of all the child node under that node. I have tried using node.isTreeExpanded to show/hide the panel. But isTreeExpanded value is always same. It is not changing on expand/collapse. Could you please help to find if the node is expanded or not?

Also is there a way to retain the expand/collapsed state of all the nodes, after save and refresh the data

If you are using LayeredDigraphLayout instead of TreeLayout, I believe your graph is not tree-structured. If that is indeed the case in your app, you should not be using the API that has “Tree” in the method or property or builder name.

There are many plausible collapse/expand behaviors when the graph is not tree-structured. Chances are that you will need to implement your own collapse and expand implementations that do not depend on the pieces of the GoJS API that have “Tree” in their name.

Have you seen this sample? Custom Expand and Collapse Buttons for Non-Tree Graphs | GoJS Diagramming Library
If it doesn’t have the behavior you want on the kinds of graphs your app will handle, you can adapt the code.

That helps. Thanks Walter.

I have added my custom logic for expand collapse nodes