Guide
Diagnosing PrimeNG p-table Pagination Failures and Data Sync Issues
Diagnose PrimeNG p-table pagination failures: check lazy, totalRecords, onLazyLoad, first, and virtualScroll with step‑by‑step fixes.
Published by Tasadduq Burney
30 Jul 2025, 17:33 UTC
2 min50.9K views0

Recognizable Condition
When using PrimeNG's p-table, pagination controls either do not change the displayed page, show an incorrect number of pages, or cause the table to go blank after a page jump.
Cause / Diagnostic Table
| Symptom | Likely Cause |
|---|---|
| Pagination buttons missing or disabled | totalRecords does not match actual data count |
| Clicking a page number does not update rows | lazy enabled but onLazyLoad not handling first and rows |
| Table shows first page correctly but subsequent pages are empty | Server returns correct slice but client‑side first not updated |
| Slow rendering with >10 000 rows | Missing virtualScroll while using local data |
Ordered Checks
- Confirm whether
lazyis set in the template. - Inspect the component class for
totalRecordsinitialization and updates. - Verify that
onLazyLoadreceives the event and usesevent.firstandevent.rowsto request the correct slice. - Check that the
firstproperty is updated after each lazy load (either by the backend returning it or by setting it locally). - If
lazyis false and row count is high, look forvirtualScrollattribute.
Fixes Tied to Findings
- Incorrect totalRecords – Set
totalRecordsto the value returned by the backend’s count API before the table renders. - Missing onLazyLoad handling – Implement the method:
onLazyLoad(event: LazyLoadEvent) { this.loading = true; this.dataService.getRows({ first: event.first, rows: event.rows, sortField: event.sortField, sortOrder: event.sortOrder, filters: event.filters }).subscribe({ next: res => { this.rows = res.data; this.totalRecords = res.total; this.loading = false; }, error: err => { console.error(err); this.loading = false; } }); } - first not updating – Ensure the backend returns the correct slice and that you assign
this.rows = res.data;(do not resetfirstmanually; PrimeNG uses the event value). - Performance degradation – Add
[virtualScroll]="'true'"(orvirtualScroll) whenlazyis false and row count > 5 000.
Escalation Criteria
- If after applying the above fixes pagination still does not work, verify PrimeNG and Angular version compatibility (e.g., PrimeNG 15.x with Angular 16+).
- Check the Network tab for non‑200 responses or malformed JSON that could cause silent failures.
- Look for console errors like
ExpressionChangedAfterItHasBeenCheckedError; if present, wrap data updates insetTimeout(() => {...}, 0)or useChangeDetectionStrategy.OnPushwith proper marks. - When the issue persists, create a minimal reproducible example and post to the PrimeNG GitHub issue tracker with version details.
Verification
- Open browser dev tools → Network, filter XHR, trigger a page change and confirm the request includes correct
firstandrowsquery parameters. - In the component, log
totalRecordsandrows.lengthafter each load; they should match the backend’s count and slice size. - Confirm that the pagination UI shows the expected number of pages:
Math.ceil(totalRecords / rows).
Limitation: This guide assumes PrimeNG ≥ 13 and Angular ≥ 12. For older versions the API names (e.g., LazyLoadEvent) may differ; adjust accordingly.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.