0

I need this type of solution for mat-tree. I tried hard but can't able to find a solution .

https://stackblitz.com/edit/angular-mat-highlight-row-on-conditions

James Z
  • 12,209
  • 10
  • 24
  • 44
Gunjan D
  • 11
  • 1
  • 3

1 Answers1

2

can not add as data to your mat-tree a new properties and change the class or the style according this new variable? -or using children if the only thing you need is mark the nodes with children

const TREE_DATA: FoodNode[] = [
  {
    name: 'Fruit',index:0,
    children: [
      {name: 'Apple',index:0},
      {name: 'Banana'},
      {name: 'Fruit loops'},
    ]
  }, ...

private _transformer = (node: FoodNode, level: number) => {
    return {
      expandable: !!node.children && node.children.length > 0,
      name: node.name,
      index:node.index, //<--DON'T FORGET THIS
      level: level,
    };
  }

<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
  <mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding 
     [style.background-color]="node.index==0?'orange':null">
    <button mat-icon-button disabled></button>
    <span >{{node.name}}</span>
  </mat-tree-node>

  <mat-tree-node *matTreeNodeDef="let node;when: hasChild" matTreeNodePadding
     [style.background-color]="node.index==0?'yellow':null">
    <button mat-icon-button matTreeNodeToggle
            [attr.aria-label]="'toggle ' + node.name">
      <mat-icon class="mat-icon-rtl-mirror">
        {{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
      </mat-icon>
    </button>
    <span>{{node.name}}</span>
  </mat-tree-node>
</mat-tree>

stackblitz

Eliseo
  • 50,109
  • 4
  • 29
  • 67
  • thank you so much I added some stuff from my and with the help of your answer its work fine thank you. – Gunjan D Jul 22 '19 at 12:07