constantin-p / cp-react-tree-table

A fast, efficient tree table component for ReactJS.
https://constantin.software/cp-react-tree-table
MIT License
95 stars 27 forks source link

Expand / Collapse until certain level #9

Closed dexter-skr closed 5 years ago

dexter-skr commented 6 years ago

Hi @constantin-p , Is there a way / method we could use to limit the expand / collapse up to certain level(depth). Like expand until the second level or expand until the third level.

Have done a rough fiddle - https://jsfiddle.net/sujaikarthik/Lystd2j9/103/. ( doesn't work as intended though. Its Just to give a clear idea on what am requesting for )

It would be really helpful, if we could have this. Thanks

constantin-p commented 5 years ago

Hi @dexter-skr,

With b25f70d11dc1a92e903455c54d7ef94d9f569c11, v0.8.1 I changed the signature of expandAll to accept a depthLimit argument.

If no value is passed, the method will work like it used to (all nodes will expand). If a value is given, only nodes that have the depth value less than or equal to the provided value will be made visible (in other words, only nodes with their depth value less than the provided value will expand).

NOTE: depth starts from 0 (root nodes have a depth value of 0 and are always visible. Their direct children have a depth value of 1 and so on).

Demo

dexter-skr commented 5 years ago

Hi @constantin-p ,

Thanks a lot. It works perfectly.

In the demo, when the tree is expanded to level 3, choosing 2 from drop-down did not collapse the tree to level-2. So I have tweaked the demo-code a bit, to have all the functionalities in the drop down. All - Expand All Root - Collapse All Numbers - Expand / collapse to the particular level

For your reference : Demo