Angular 4 Material table highlight a row

后端 未结 7 1693
栀梦
栀梦 2020-12-08 06:14

I\'m looking for a good way to highlight the whole a row in md-table.
Should I do directive or what?



        
相关标签:
7条回答
  • 2020-12-08 07:04

    This will allow you to select multiple rows if the row is not previously selected and on clicking again it will deselect it.

    HTML

    <mat-row *matRowDef="let row; columns: displayedColumns;"
      (click)="findOut(row)"[style.background]="highlightedRows.indexOf(row) != -1 ? 'lightgrey' : ''"></mat-row>
    

    Type Script

    Create an array

    highlightedRows = [];
    

    Define the findOut function

    findOut(row){
      if(this.highlightedRows.indexOf(row) === -1){
        this.highlightedRows.push(row);
        }
        else{
        
          this.highlightedRows[this.highlightedRows.indexOf(row)] = -1;
        }
        
      }
    
    0 讨论(0)
提交回复
热议问题