Event to get notified when a node gets expaneded
Hello,
I was wondering if there is an event to get notified when a node gets expanded or collapsed. I need this to write a custom function to keep the list of expanded states. I couldn't find any function to restore expanded nodes after a page refresh
Thanks for your suggestion. There is no such event right now. I think if we would add it, we will some other related methods as well to make this feature complete, such as editor.getExpandedNodes(), editor.setExpandedNodes().
Can you explain your use case? If we have a clear view on that, we can think though a good solution.
the idea is to restore expanded states when browser restarts or when the page reloads
That makes sense indeed. Then, maybe methods like getState() and setState() makes sense. It could contain the expanded nodes, but maybe also the scroll position and the selection.
That would be perfect!
Sounds good.
Anyone interested in implementing a getState and setState? I think it requires some thinking though of the details before actually implementing something. Help would be very welcome.
editor.getState() and editor.setState() might be useful but they serve different use case compared to getting notified in case of a node expanded/collapsed event. Can we have something like onExpand(path, isExpanded) callback passed to the options while creating a JSONEditor, which allows us to execute whatever we want in case a node is expanded/collapsed ?
So, I'm trying to use two instances of JSONEditor to show JSON diff and I want to sync the node expand/collapse operations across the editors, but couldn't find a way as of now. Having onExpand callback and another editor.expand(path, isExpand) method would allow me to implement my use case.
Any plans of implementing this or comments on the use case (can this be achieved with the current APIs) ?
Thanks for your input @himanshu520 . I like your proposal of an onExpand(path, isExpanded) and editor.expand(path, isExpand), this is much simpler to implement than a big, generic getState and setState.
Both these methods do not yet exist, the only thing that comes close is the editor.exapndAll() function 😄
I'm not planning on implementing this myself any time soon, help implementing this would be welcome.