Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get index with PrimNG TurboTable and Angular 6

I cant figure out how to get an index with Angular 6 and PrimeNG turbo table.

this is my best guess on how it should work.

<p-table [value]="timecards">
  <ng-template pTemplate="body" let-timecard let-i="index">
    <tr><td>{{ i }}</td><td>{{ timecard.value }}</td></tr>
  </ng-template>
</p-table>

But I have also tried this

<p-table>
  <ng-template pTemplate="body" ngFor let-timecard let-i="index" [ngForOf]="timecards>
    <tr><td>{{ i }}</td><td>{{ timecard.value }}</td></tr>
  </ng-template>
</p-table>

And this

<p-table [value]="timecards">
  <ng-template pTemplate="body" ngFor let-timecard let-i="index" [ngForOf]="timecards>
    <tr><td>{{ i }}</td><td>{{ timecard.value }}</td></tr>
  </ng-template>
</p-table>

And several other combinations. I can't get any of them to work.

like image 640
Jared Whipple Avatar asked Dec 10 '22 04:12

Jared Whipple


1 Answers

The property you are looking for is let-rowIndex as described by the PrimeNG TurboTable documentation:

<p-table [value]="timecards">
  <ng-template pTemplate="body" let-timecard let-rowIndex="rowIndex">
    <tr><td>{{ rowIndex }}</td><td>{{ timecard.value }}</td></tr>
  </ng-template>
</p-table>
like image 196
Gordon Westerman Avatar answered Dec 29 '22 07:12

Gordon Westerman