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

DataView: Paginator prop watcher timing issue #5608

Open
SamuelWei opened this issue Apr 17, 2024 · 0 comments
Open

DataView: Paginator prop watcher timing issue #5608

SamuelWei opened this issue Apr 17, 2024 · 0 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@SamuelWei
Copy link

SamuelWei commented Apr 17, 2024

Describe the bug

The paginator of DataView and DataTable can be controlled by the props totalRecords, rows and first.

In case the data is lazy loaded, sorting, filtering, etc. is done on serverside, these values are updated based on the servers response.

The Paginator component has three watchers to check for changes in any of the three props (https://github.com/primefaces/primevue/blob/master/components/lib/paginator/Paginator.vue#L81:L93)

In case the index of the first entry on the current page (first) is higher than the totalRecords the page is changed to the last possible page. (see https://github.com/primefaces/primevue/blob/master/components/lib/paginator/Paginator.vue#L88:L91)
This makes sense, however in case totalRecords and first are updated at the same time, this will also trigger the page change behavoir, even if the new first value is lower than totalRecords because the totalRecords-watcher is still using the old first value.

If you also add @page to DataView to request content of a different page on manual page change via the paginator, this bug will cause a second request.

Reproducer

https://stackblitz.com/edit/w1mnbh?file=src%2FApp.vue

PrimeVue version

3.51.0

Vue version

3.x

Language

ALL

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

  1. Go to the last page
  2. Apply the filter (Button on the top left)
  3. See 4. page is shown

Expected behavior

  1. Go to the last page
  2. Apply the filter (Button on the top left)
  3. See 1. page is shown (as the request with the filter requests page=1)

How to fix?

A temp. workaround is to add an artificial delay, to first update the first prop and than the totalRecords prop.

 ProductService.getProducts(params).then(async (response) => {
    products.value = response.data;
    // First update the from (first) value
    meta.value.from = response.meta.from;
    // Add delay, so the paginator can already change to the correct new page
    await nextTick();
    // Apply all other paginator changes
    meta.value = response.meta;
  });
@SamuelWei SamuelWei added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 17, 2024
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

1 participant