简体   繁体   中英

Highlight specific line in Angular Material Table

I have a angular material table:

  <ng-container matColumnDef="index">
    <th mat-header-cell *matHeaderCellDef>Index</th>
    <td mat-cell *matCellDef="let element"> {{element.index}} </td>
  </ng-container>

  <ng-container matColumnDef="time">
    <th mat-header-cell *matHeaderCellDef>Time</th>
    <td mat-cell *matCellDef="let element"> {{element.Time}} </td>
  </ng-container>

  <ng-container *ngFor="let quantity of quantities" >
    <ng-container [matColumnDef]="quantity.name">
      <th mat-header-cell *matHeaderCellDef>{{quantity.name}}</th>
      <td mat-cell *matCellDef="let element"> {{element[quantity.name]}} </td>
    </ng-container>
  </ng-container>


  <tr mat-header-row *matHeaderRowDef="columns; sticky:true"></tr>
  <tr mat-row *matRowDef="let row; columns: columns;"></tr>
</table>

and I want to highlight specific line when I click a button in my screen. I tried to find a solution on the web and I didn't find any way to do that. If that possible?

Thank you very much for your help and have a nice day,

Amit.

Do something like this:

<tr mat-row *matRowDef="let row; columns: columns;" [class.highlight]="row.field===specificLine"></tr>

And in the component's style flie:

tr.highlight { background-color: red; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM