Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I read which nodes are expanded? #398

Open
ldm-acn opened this issue May 10, 2024 · 2 comments
Open

How can I read which nodes are expanded? #398

ldm-acn opened this issue May 10, 2024 · 2 comments

Comments

@ldm-acn
Copy link

ldm-acn commented May 10, 2024

I need to read which nodes are expanded when I click a button in the page that is rendering my orgchart.

To do so I pass a reference to the same data object I pass to d3 and check if the _expanded flag is set, this gives me a value of true if the node is expanded and a value of undefined otherwise.

My issue is that for the nodes that are already visibile when the tree first renders the value is always undefined.

If I hide all the nodes exepct the root the values are then set to false for all the nodes.

After that if I expand again the tree the value for all nodes except the root are set to true when I would exepect them to, but the value for the root alwys stays on false.

I also tried checking the expanded, _children, children, _centered and centered flags for all nodes and they always are undefined. In fact, the only property that is set when interacting with the tree is _expanded.

Is there a way that I can check with nodes are open on the orgchart at any given time?

@bumbeishvili
Copy link
Owner

bumbeishvili commented May 10, 2024

If the node parent has .children property, then the current node is expanded, otherwise if the node parent has _children property then current node is collapsed

@ldm-acn
Copy link
Author

ldm-acn commented May 10, 2024

You're right that I can get that info from the handlers implemented by the library like onNodeClick and onExpandOrCollapse.

Since I was seeing the _expanded property being modified in the original data object I had hoped that I could have access to the same data from outside the methods of OrgChart.

This seems to be an unintended side effect and the data object itself is (correctly) cloned for internal use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants