primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Lazy DataTable recursive LazyLoadEvent

Open gorokhmn opened this issue 9 years ago • 5 comments

I'm submitting [x] bug report => Search github for a similar issue or PR before submitting [ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap [ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Current behavior The DataTable is declared in html as

[value]="rows"
[lazy]="true"
(onLazyLoad)="loadPageLazy($event)"
[totalRecords]="totalRecords"

The component.ts is implemented as:

loadPageLazy(event: LazyLoadEvent) {
  this.gridService.getPage(JSON.stringify(event)).subscribe((result: any) => {
    this.rows = result.rows;
    this.totalRecords = result.totalRecords;
  });
}

The function loadPageLazy() is called recursively/endlessly if some particular filters are specified in UI, for example, not null combobox filter value with non-empty page rows result.

Workaround solution Implement function loadPageLazy() with validation for duplicate identical reloads

jsonLazyLoadEventLast: string;
loadPageLazy(event: LazyLoadEvent) {
  let jsonLazyLoadEvent = JSON.stringify(event);
  if (this.jsonLazyLoadEventLast === jsonLazyLoadEvent) {
    return;
  }
  this.jsonLazyLoadEventLast = jsonLazyLoadEvent;
  this.gridService.getPage(jsonLazyLoadEvent)).subscribe((result: any) => {
    this.rows = result.rows;
    this.totalRecords = result.totalRecords;
  });
}

Expected behavior LazyLoadEvent should be triggered once without recursions for any filters and result page rows.

Please tell us about your environment: PrimeNG 2.1.1 Angular 2.4.0 Browser: Chrome 56.0.2924.87

gorokhmn avatar Feb 10 '17 16:02 gorokhmn

I have the same problem, when I filter for something, it is recursively calling my (onLazyLoad) function. It seems to be the same problem like #1434 and #1502

My enviroment is: PrimeNG 4.0.0-rc.2 Angular 4.0.1

igogu avatar Apr 06 '17 15:04 igogu

Also happens with: PrimeNG 4.0.0-rc.3 Angular 4.0.1

miniplus avatar Apr 18 '17 07:04 miniplus

Can confirm that this happens with: PrimeNG 4.0.0-rc.3 Angular 4.0.1

Thank you @gorokhmn, your fix works for me

buoyad avatar Jun 08 '17 18:06 buoyad

The issue seems to be resolved in PrimeNG 4.0.3 + Angular 4.1.3

gorokhmn avatar Jun 08 '17 19:06 gorokhmn

This should be fixed in recent PrimeNG release, please try with it and if the issue persists drop a comment with along with a test case based on plunkr below and we'll review again.

http://plnkr.co/edit/Wj39h1?p=preview

cagataycivici avatar Jun 20 '17 12:06 cagataycivici