S
S
Sergei Abramov2019-12-04 18:17:51
Angular
Sergei Abramov, 2019-12-04 18:17:51

How to expand the whole branch of a tree in mat-tree?

I study cdk mat-tree: https://material.angular.io/cdk/tree/overview
I need to find matches in the tree and open the entire branch. before this coincidence. Finding is not a problem. Opening the right one is the same, but here's how to open it in a chain, up to the root parent? When I made my tree, I added the parent property - which referred to the ancestor and opened it recursively. And then how to be?
Example: https://stackblitz.com/edit/angular-yi9tbm-bzq6wu with line 81 commented out, the branch opens when the button is clicked, but we do not see this, because the parent is collapsed. How to open with a chain?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-12-04
@PatriotSY

it's a flat tree. You just take a node, expand it and move back through the array expanding the nodes until you get to level 0
here
https://stackblitz.com/edit/angular-yi9tbm-i9tl2k
or even like this

private expandAcsendants(index: number) {
  for (let c = index; this.treeControl.dataNodes[c]; c--) {
    this.treeControl.expand(this.treeControl.dataNodes[c]);
    if (this.treeControl.dataNodes[c].level === 0) {
      break;
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question