I have a very large amount of data (400.000 records) that I need to show in a PrimeNG data table. For this I need a lazy loading table, since you cannot load all data into the table in one time (this will make your browser crash).
For creating the table I am using the following technologies:
- 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
What do I want
I am trying to create a lazy loading table as shown in the PrimeNG docs, where the data is loaded from the server and shown in table. When the user navigates to the next tab the next x amount of data is loaded and shown.
The only difference is that I fetch all the data from the server before giving it to the table component. This way I will only have to pick certain data from the datasource and show it to the user.
The problem
While trying to implement it I ran into the problem that the (onLazyLoad)
function is only called once, in the onInit()
phase, before the data is loaded from the server.
I can undo this by adding [lazyLoadOnInit]="false"
, but this results in the lazy load function not being called at all. I was hoping I could trigger the load function by changing the [totalRecords]
property when the data is loaded, but this also doesn't trigger the function.
I cannot find any other function in the PrimeNG p-table code that I could use for triggering the (onLazyLoad)
, or am I missing something?
Code
public ngOnInit(): void {
this.cars$ = this.carService.entities$; // = []
this.carService.getAll(); // = [Car, Car, Car, Car] OR []
}
this.carService.entities$
has a default value of []
and is populated with the result of the getAll()
function (this can also be []
if there are no results)
I have reproduced my problem in a StackBlitz. Here you can see that the data is never shown, because the (onLazyLoad)
is only called the first time, when the data is empty.
Note that I am using the Angular Async pipe for passing the data into my component. This means I need to check the changes in a ngOnChanges()
function.
ChangeDetectionStrategy.OnPush
when you use async pipe when you use blog.angularindepth.com/… – Rigney