I have a significant amount of data (400,000 records) that I need to display in a PrimeNG data table. In order to prevent browser crashes, I am looking to implement lazy loading functionality for the table which allows the data to be loaded gradually.
The technologies I am utilizing for creating this table include:
- Angular
7.2.4
- Angular/cdk
7.3.1
- ngrx-data
6.1.0-beta.3
(Ngrx http request wrapper) - PrimeNG
7.0.5
(UI Framework) - Rxjs
6.4.0
Objective
My goal is to develop a lazy loading table similar to the one illustrated in the PrimeNG documentation. The data should be fetched from the server and displayed in the table incrementally as the user navigates through different sections.
The slight variation I intend to implement involves pre-fetching all data from the server before feeding it to the table component. This approach will allow me to select specific data from the datasource and present it to the user.
Issue at Hand
During my implementation efforts, I encountered a problem where the (onLazyLoad)
function is only triggered once during the OnInit()
phase before data retrieval from the server. Adding [lazyLoadOnInit]="false"
prevents the function from being called altogether. Despite attempting to modify the [totalRecords]
property upon data retrieval, I was unable to trigger the function.
I couldn't find any other suitable function within the PrimeNG p-table code to activate the (onLazyLoad)
function. Am I overlooking something?
Code Snippet
public ngOnInit(): void {
this.cars$ = this.carService.entities$; // = []
this.carService.getAll(); // = [Car, Car, Car, Car] OR []
}
this.carService.entities$
initially holds a value of []
and gets populated with the outcome of the getAll()
function call (it could also remain []
if there are no results).
To illustrate the issue, I've created a demonstration in StackBlitz. You'll notice that the data isn't displayed because the (onLazyLoad)
event is only fired once when the initial data is empty.
It's worth noting that I'm employing the Angular Async pipe for transmitting data into my component, necessitating monitoring changes within an ngOnChanges()
function.