Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component: p-table - subsequent sorts do not update source value #15722

Closed
lfpraca opened this issue May 28, 2024 · 1 comment
Closed

Component: p-table - subsequent sorts do not update source value #15722

lfpraca opened this issue May 28, 2024 · 1 comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@lfpraca
Copy link

lfpraca commented May 28, 2024

Describe the bug

Using the "sort" example in table, the first time the table is sorted, the "products" variable, which is passed as the "value" attribute to p-table, is sorted according to the selected sort option, however, this does not happen on any subsequent sorts, staying how it was after the first sort.

Forcing an update such as by doing this.products = [...this.products]; on the (onSort) event makes the p-table ngOnChanges run (I suppose) which makes it correctly sort the products variable. However the expected behaviour is that this would happen without the need to force this update.

Environment

This was first noticed on a standard angular v17 production project, but can be reproduced in e.g. stackblitz

Reproducer

https://stackblitz.com/edit/mulxe5-psdggj?file=src%2Fapp%2Ftable-single-column-sort-demo.html,src%2Fapp%2Ftable-single-column-sort-demo.ts

Angular version

17.3.8

PrimeNG version

17.17.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.9.0

Browser(s)

No response

Steps to reproduce the behavior

In the stackblitz project linked above:

  1. See that the "products" data source is being correctly sorted after clicking on the sort buttons on the header

  2. Comment "table-single-column-sort-demo.ts"'s line 25 (this.products = [...this.products];)

  3. See that the "products" data source is only being correctly sorted after clicking the sort buttons on the header the first time, and after that it does not get sorted again when clicking the sort buttons again. (note that the table itself keeps getting correctly sorted, it is just the "products" variable that does not get sorted)

For cases without the stackblitz project linked above:

  1. Copy the code in the documentation

  2. Add a function to print the "products" data source after sorting

  3. Notice that the "products" variable only gets sorted the first time

Expected behavior

It would be expected that the variable used as the data source via the p-table's "value" property would get sorted every time there is a sorting action, not just the first time.

@lfpraca lfpraca added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label May 28, 2024
@mertsincan
Copy link
Member

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

2 participants