I have searched the web for a decent example of primeng datatable with rowTrackBy. Documentation is incomplete and does not say much. Is there anyone out there that can help?
Asked
Active
Viewed 5,742 times
2 Answers
8
Just wanted to show where and how to use rowTrackBy in table template as well in this answer:
<p-table #tt [value]="data" [lazy]="true" (onLazyLoad)="loadDataLazily($event)" [paginator]="true"
[rows]="dataSize" [totalRecords]="totalRecords"
[rowsPerPageOptions]="[10,20,30]" [rowTrackBy]="trackByFunction">
trackByFunction = (index, item) => {
return item.id // O index
}

DirtyMind
- 2,353
- 2
- 22
- 43
5
It's very similar to the trackBy function in ngFor. You just need to provide a function with the index and the item as arguments and you return what you are tracking by. For example
trackByFunction = (index, item) => {
return item.id // O index
}

Carlos Angarita
- 161
- 3
- 11