Angular material tree expand a particular node

15,820

What you are looking for is the expand method on treeControl, which operates on the treeControl.dataNodes array.

Something like

this.treeControl.expand(this.treeControl.dataNodes[/** node you want to expand **/]);

Just keep in mind that if you want to expand a particular node, all its ancestors up to the root need to be expanded as well.


Demo

Share:
15,820
androidGenX
Author by

androidGenX

Like to try different languages. Likes R&D. Now sticking to java. Have worked on ios, android, php before.

Updated on July 21, 2022

Comments

  • androidGenX
    androidGenX almost 2 years

    I have seen various examples to expand all nodes in mat-tree using

    expandAll()
    

    Is there any mechanism to expand a particular node if we click on it. Something like

    node.expand()
    

    I had referred angular material documentation but not got any answer. Please guide if anyone gone through it.

  • Nayan Hodar
    Nayan Hodar about 4 years
    How to expand all parent node of particular child node in nested tree control in angular 8??? I used this code with some extra fields modification stackblitz.com/angular/…
  • C0mpl3x
    C0mpl3x about 3 years
    What is I want to pass in a specific node to open that was clicked. How do I do that. I cannot pass the node because your sollution need index.