I'm trying to get the index of row in table, in html, which has been implemented using angular material v5.2. Is there any method available to get the index?
The code for reference:
<div class="example-container mat-elevation-z8">
<div class="example-header">
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
</div>
<mat-table #table [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="position">
<mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.position}} </mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<button (click)="doSomething()"> Do something</button>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</div>
The method doSomething is what needs index.
Any help would be greatly appreciated.
element
), you don't need to declare it. You can just do<td mat-cell *matCellDef="let i = index">{{i}}</td>
– Bondsman