maxazan/jquery-treegrid

How do I implement savestate and a expand/collapse all button?

Closed this issue · 2 comments

Hi there - thanks for this treegrid! As a JS beginner I have a few basic issues with adapting the tree to my needs.
Firstly, I like to know how I can trigger $('#tree').treegrid('expandAll'); with a button or a checkbox for example. Can somebody help?
Secondly, savestate is not working if applied as shown in the savestate example. initialState works however, but if I insert the savestate : true line, all the node arrows disappear, so there must be some issue here.
Thanks for help! Frank

Try (example):

HTML (you can use a button element as well):
<a href="#" id="pagetree-expand-all">Expand all</a>

jQuery:
$('a#pagetree-expand-all').on('click',function(e) {
$('.treetable').treegrid('expandAll');
});

Make sure the ID is unique!

Thank you for this example, webbird :-) In the meantime maxazan helped me with my problem. "expand all" didn't work on my site as it had some html errors - after removing some redundant span tags it worked.

savestate didn't work even though implemented as shown in the example - after adding the jquery.cookie.js reference it worked right away :-)

Hope this helps also other users. Regards, Frank