41
Views
3
Comments
Solved
[zTree] Save the collapse and expand it in a session variable
ztree
Web icon
Forge asset by Eduardo Luís

Hi!

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.


Thanks

2022-06-17 09-22-26
Huarlem Lima
Solution

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

KeepExpanded.oml
UserImage.jpg
Danilo Vilarinho

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.

Thanks

Capturar.PNG
UserImage.jpg
Danilo Vilarinho

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);


         } "

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.