Skip to content

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

@oliP7

Description

@oliP7

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: Help WantedIssue or pull request requires extra help and feedback

    Type

    No type

    Projects

    Status

    Review

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions