Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add click event on mat-row in angular material table

I added this but when inspecting element using Chrome DevTools, the click function doesn't show!

Here's my code:

  <mat-table [dataSource]="dataSource1" class="mat-table">     <!-- Position Column -->     <ng-container matColumnDef="Objname">       <mat-header-cell *matHeaderCellDef> ObjName </mat-header-cell>       <mat-cell *matCellDef="let element"> {{element.objname}} </mat-cell>     </ng-container>     <!-- Weight Column -->     <ng-container matColumnDef="Successcount">       <mat-header-cell *matHeaderCellDef> Successcount   </mat-header-cell>       <mat-cell *matCellDef="let element"> {{element.successcount}} </mat-cell>     </ng-container> <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>     <mat-row (click)="getRecord(element.objname)" *matRowDef="let row; columns: displayedColumns;"></mat-row>   </mat-table> 
like image 444
Vyas Reddy Avatar asked Jan 09 '18 08:01

Vyas Reddy


1 Answers

almost the same solution as above but a bit more useful if you are trying to get the object from the clicked row

<mat-row  *matRowDef="let row; columns: displayedColumns;" (click)="getRecord(row)"></mat-row> 

when you console log the row you will get the entire object of the row

like image 135
Jonathan Meguira Avatar answered Sep 20 '22 09:09

Jonathan Meguira