PrimeNg p-table组件lazyLoadOnInit属性设置为false仍触发初始加载问题求助
lazyLoadOnInit="false" Not Working Let me walk through some common reasons why this might be happening and how to fix them:
1. You haven't enabled lazy loading mode
The lazyLoadOnInit property only takes effect when lazy mode is explicitly turned on with [lazy]="true". If you skip this flag, the table won't enter lazy loading mode at all, and the lazyLoadOnInit setting will be completely ignored.
Double-check your table template to ensure you have both critical attributes:
<p-table [lazy]="true" [lazyLoadOnInit]="false" (onLazyLoad)="loadData($event)" [totalRecords]="totalRecords" > <!-- Your column definitions here --> </p-table>
2. Accidental triggers from other table properties
Sometimes default values for pagination or sorting can inadvertently fire the onLazyLoad event even with lazyLoadOnInit="false". Common culprits include:
- A default
[first]value set to something other than0 - Predefined
sortFieldorsortOrderbindings
To rule this out, temporarily remove any default pagination/sort configurations and test if the initial load stops.
3. Manual invocation of load logic in your component
Check your component's ngOnInit or constructor to make sure you're not manually calling your loadData function (or the table's built-in reset()/load() methods) on initialization. This would bypass the lazyLoadOnInit setting entirely.
4. Potential bug in the latest PrimeNG version
Since you're using the latest version, there's a chance a regression or bug is affecting the lazyLoadOnInit behavior. You can check the PrimeNG GitHub repository for open issues tagged with p-table and lazyLoadOnInit to see if other users have reported the same problem. If it's a confirmed bug, you might need to roll back to a previous stable version or wait for an official patch.
Quick isolation test
Try creating a minimal reproduction with just the basic lazy table setup (no extra features like custom sorting, filters, or pagination defaults). If the issue persists here, it's likely either a configuration oversight or a framework-level bug.
内容的提问来源于stack exchange,提问作者Developer Thing

