4

I am having an issue when adding index to my table rows. I have assigned index value like this:

<ng-container matColumnDef="id">
  <mat-header-cell *matHeaderCellDef>#</mat-header-cell>
  <mat-cell *matCellDef="let i = index"> {{i+1}} </mat-cell>
</ng-container>

This solution is working on one table but on the second table it is returning NaN. Does anyone knows how to fix this?

On the second table I am using expandable rows so I have added multiTemplateDataRows attribute. Everything else is the same. I am using Material Design v7.11

1 Answer 1

18

As you are using multiTemplateDataRows property , you can't use index. Instead you have to use dataIndex or renderIndex.

<mat-cell *matCellDef="let i = renderIndex;">{{i+1}}</mat-cell>
Sign up to request clarification or add additional context in comments.

2 Comments

Thannk you! Adding dataIndex instead of index solved my issue.
Amidst of coronavirus. I found this. Thanks my friend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.