ember-simple-tree icon indicating copy to clipboard operation
ember-simple-tree copied to clipboard

onExpand/onCollapse callback

Open jandillmann opened this issue 6 years ago • 3 comments

I'd like to store the tree's state (expanded, collapsed) in local storage, but I don't think there are callbacks for these events yet. Would it be possible to add these, or is there another way to achieve this?

jandillmann avatar Sep 07 '19 14:09 jandillmann

In your parent component that uses x-tree, you could save the state when you're about to destroy the component / leave the route. That way, you don't have to update your localStorage after every single change but in bulk. Use the isExpanded property. That should, work, correct?

btecu avatar Sep 08 '19 17:09 btecu

Thank you for this suggestion, however I don't think it's a solution for my usage. The tree component is shown on the left of the Ember app as a navigation sidebar and visible at all times, so the website (tab / browser window) is much more likely to be closed than being navigated away from. Additionally, users can add new elements to the tree, which currently reloads the whole model and therefore renders a new tree with the newly inserted element. This also resets the isExpanded properties, i.e. all collapsed elements then suddenly expand again.

jandillmann avatar Sep 09 '19 06:09 jandillmann

Could also be useful to implement tree lazy loading.

lodrantl avatar Apr 01 '20 16:04 lodrantl