Search code examples
angularprimengprimeng-treetable

How to expand PrimeNg TreeTable by code


Assuming I have a TreeTable provided by PrimeNg for Angular2. How can I expand a particular node in code (for example in onNodeSelect callback)?


Solution

  • I guess the OP no longer needs the answer, but for anyone who reaches here and finds no answer -

    There is a property expanded for TreeNode, all you need to do is just set it to true

    selectedNode.expanded=true;
    

    And if you want the tree to be shown all expanded, just traverse the TreeNodes and set expanded on each. Which will be something similar to this

      expandChildren(node:TreeNode){
        if(node.children){
          node.expanded=true;
          for(let cn of node.children){
            this.expandChildren(cn);
          }
        }
      }