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?
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
}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With