primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.62k stars 4.62k forks source link

p-table emits multiple lazyLoading events when we have dynamic [sortField] #12595

Open oliP7 opened 1 year ago

oliP7 commented 1 year ago

Describe the bug

We have component template that looks like this: <p-table [scrollable]="true" scrollHeight="flex" responsiveLayout="scroll" [columns]="header" [value]="items" [paginator]="true" [rows]="config.pageSize" [pageLinks]="config.pageLinkSize" [rowsPerPageOptions]="[10, 50, 100, 200]" [totalRecords]="config.totalCount" [lazy]="true" (onLazyLoad)="onLazyLoading($event)" [sortMode]="'single'" [sortField]="settings.sortField" [sortOrder]="settings.sortOrder" (onRowSelect)="onRowSelected($event)"> . . . </p-table>

Almost all the columns that I have are sortable and filterable. When I initially load the table the sortField and the sortOrder are null. The first problem that I have is every time when I click the sort icon from the table header the lazy loading function is called 2 times therefore we have 2 backend calls. Another problem is also when I have some sort applied and save the table state and than when I come back to this page restore the state I also have 2 lazy loading calls. Is there a way to restore the table state without extra calls. Is there a way to tell the table that there is a pre selected sort column and the table to mark this column without triggering onLazyLoading call ? Ideally would be whenever I do table.sortField = settings.sortField; table.sortOrder = settings.sortOrder the table to mark them as selected or highlighted.

Environment

Windows 11 Pro Processor AMD Ryzen 7 5700U with Radeon Graphics 1.80 GHz Installed RAM 16,0 GB (14,8 GB usable) System type 64-bit operating system, x64-based processor

Reproducer

No response

Angular version

14.2.10

PrimeNG version

14

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

16.16.0

Browser(s)

Chrome

Steps to reproduce the behavior

No response

Expected behavior

No response

sinalkaMP commented 1 year ago

Having the same issue, found no way to pre-set the table sort (also visible to the user) without triggering the lazyLoad twice. Pre setting the filters and pagination works perfectly, but the sorting always causes more http calls than I want.

Larissa29 commented 1 year ago

Just run into the same issue. Any update on that?

aabruc commented 3 months ago

We're faced with the same issue (twice lazy loading) with the combination of column filter and sort. IIf a column filter is present in the LazyLoadEvent, sorting triggers loading twice. This is actually with a higher PrimeNg version: 17.18.6. https://github.com/primefaces/primeng/issues/16182

ivan-price-acted commented 2 months ago

hi there, just leaving a note to say we had this problem too and it was indeed fixed when this was fixed: https://github.com/primefaces/primeng/issues/16182

We're now running [17.18.9] and the "double-api-call-on-sort" has gone away :)

for me this issue can be closed.

ilkomiliev commented 1 month ago

hi there, just leaving a note to say we had this problem too and it was indeed fixed when this was fixed: #16182

We're now running [17.18.9] and the "double-api-call-on-sort" has gone away :)

for me this issue can be closed.

I am on 17.18.10 and the issue still exists. We have implemented restore of the table state from the localstore, because of the other long-standing bug, that the sort field is not restored, and this triggers the lazy load event twice - once with the initial values for sortField and sortOrder and a second time with the restored values, IF they are different from the initial once.

github-actions[bot] commented 1 week ago

Due to PrimeNG team's busy roadmap, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. :sparkles: Thank you for your contribution! :sparkles: