[zTree] Save the collapse and expand it in a session variable
Forge component by Eduardo Luís
Published on 03 Oct 2019


How to store in a session variable if a given node in the tree has been expanded or collapsed and also store the id of that node?

The intention is for the user to refresh the page and the tree will be as it was before the refresh.


Rank: #69

Hi Danilo,

To store the selected node, you can use the CallBack OnClick function, as in the image below;

To expand the specific node, it was necessary to create a custom javascript, as the component does not have one.

I added an OML with these customizations


Rank: #14379

Good Morning!

Huarlem, I implemented with your suggestion. What is not happening, which may not have been clearer in my difficulty, is that the tree does not keep, if it was once collapsed or expanded.

I can do this using the node ID when building the tree and set it to the "isOpen" property. If the ID is the same as the one selected, it sets the setting I want.

Wouldn't there be a way to get the (+) or (-) element? Thus, it would not be necessary for me to click on any node to know which node will be collapsed or expanded.

As the attached image follows.



Rank: #14379

I found a solution.

I will use Multi_02_ClickToExpand. With that I can get the ID with the Huarlem implementation and use this JavaScript inside my onclick callback to expand or collapse that particular node in the tree.

"function (e, treeId, treeNode) {

             var zTree = $ .fn.zTree.getZTreeObj (treeId);

             zTree.expandNode (treeNode);

         } "