how to define index in angular material table

Can you add index to let element; let i = index;" as you’d do with *ngFor?

<mat-row *matRowDef="let row; columns: displayedColumns; let i = index"></mat-row>

Or like so:

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

Working Example: https://stackblitz.com/edit/angular-acdxje?file=app/table-basic-example.html

Leave a Comment