1 Reply Latest reply on Dec 6, 2007 11:14 AM by domelq

    Expand Tree Nodes

    pankaj.ghosh

      Hi all,

      Is there a way to expand(or collapse) Nodes of a tree, from client side(using javascript)?

      Basically if a tree has many levels, it is difficult to navigate to each node and expand, I was wondering if there is a way to expand(or collapse) all nodes at a tree level by a click of a button.

      If not client side, I can also try doing it on server side and see if it is fast enough.

      Any pointers or suggestions?

      Thanks in advance
      Pankaj

        • 1. Re: Expand Tree Nodes
          domelq

          Hi i did it on client side just see the code bellow. I think also that somehow you could get state of a tree from stateVar attribute instead of hardCoded 'Richfaces_Tree_tree_tree'. The name of a tree on client side can be checked in DOM Window object

          
          function collapseAll() {
           var tree = window['Richfaces_Tree_tree_tree'];
           var childs = tree.childs;
           collapse(childs);
          }
          
          function expandAll(){
           var tree = window['Richfaces_Tree_tree_tree'];
           var childs = tree.childs;
           expand(childs);
          }
          
          
          
          function collapse(childs) {
           for (var i = 0; i < childs.length; i++) {
           var element = childs;
           var cc = element.childs;
           if (cc.length != 0) {
           if (!element.isCollapsed()){
           collapse(cc);
           element.eventCollapsionClick();
           }
           }
           }
           }
          
           function expand(childs) {
           for (var i = 0; i < childs.length; i++) {
           var element = childs;
           var cc = element.childs;
           if (cc.length != 0) {
           if (element.isCollapsed){
           element.eventCollapsionClick();
           expand(cc);
           }
           }
           }
          }
          

          Hope this will help