CarlosNZ/json-edit-react

Collapse events and setting collapse

Closed this issue · 4 comments

Hi,

Is it possible to have a onCollapse event, or be able to set which nodes are collapsed, what we are trying to do is save which nodes are expanded so when the user comes back to the page they won't have to re expand the tree to where they left off?

Good suggestion, and should be fairly easy to implement. I'll have a play around and keep you posted.

Hi @Jack-skitt, sorry for the slow progress on this. Just thinking about it -- I can easily at an onCollapse event, but not sure that would be enough for your use case. You'll be able to record the state of nodes as they are collapsed/expanded, but I'm not sure how you'd restore them all when reloading. Or were you thinking we could add a mechanism to trigger collapse/expand from outside the component as well?

Hi @Jack-skitt -- I have made an initial version of this functionality and have a beta available if you'd like to try it out: https://www.npmjs.com/package/json-edit-react/v/1.25.0-beta1

See the documentation for "External control" for how to implement it.

Hopefully it works for you, though completely capturing the collapse state and re-initialising it might be a bit too complex -- let me know how it goes, and if you have any suggestions for improvement before I make an official release.

Done in #182 and released in v1.25.0