4
votes

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?

2

2 Answers

5
votes

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
}
4
votes

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
}