mistletoe
mistletoe

Reputation: 493

How to add row number or Serial no in angular2 datatable

I am using angular2 -datatable.

I am not able to display correct row no.s in the corresponding rows.

The datatable starts counting from one again when the user moves to the next page using paginator.

My html code:

                <tbody>
                <tr  *ngFor="let item of mf.data; let i =index">
                    <td>
                        {{i+1}} 
                    </td>
                    <td>{{ item.name }}</td>
                    <td>{{item.department}}</td>
                    <td >{{item.category}}</td>

                </tr>
                </tbody>

Upvotes: 0

Views: 4326

Answers (2)

Pengyy
Pengyy

Reputation: 38191

try {{data.indexOf(item) + 1}}, here I suppose data is the variable you bind to <table> by <table [mfData]="data | filter "

this will get the original index from array of data.

plunker demo.

Upvotes: 2

Ali Shahzad
Ali Shahzad

Reputation: 5332

You need to calculate it with currentPage (current page number) and itemsPerPage (number of item to show per page):

{{ itemsPerPage * (currentPage - 1) + i + 1 }}

Upvotes: 1

Related Questions