2
votes

I want to implement PrimeNG DataTable LazyLoading in Angular 2 but there is no realtime example i found on internet.

I have already referred below PrimeNG site which shows lazy loading with dummy data: https://www.primefaces.org/primeng/#/datatable/lazy

Has anyone implemented by calling BE service? Please help.

1

1 Answers

1
votes

You need to add a service for this if you use angular cli you can add with

ng generate service services/CarService

after that you need to call service (maybe web api) then you need to inject your service to you lazy load component

constructor(private carService: CarService) { } 

then you can use your lazyload datatable. In this example your web api need to return data cars and totalcars(for pagination)

this.carService.getCarsLarge().then(cars => {
            this.datasource = cars; 
            this.totalRecords = this.datasource.length;
            this.cars = this.datasource.slice(0, 10);
        });