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

[Paginator] When Updated length is "shorter" than the pageIndex (*pageSize), pageIndex should be updated and then a pageEvent to the pageIndex emited #14520

Open
hannaseithe opened this issue Dec 14, 2018 · 5 comments · May be fixed by #14625
Labels
area: material/paginator P4 A relatively minor issue that is not relevant to core functions

Comments

@hannaseithe
Copy link

What is the expected behavior?

When I am on the last Page of a dataSet and then delete the elements that are currently showing (or filter elements "away"), and thereby change the length property, the paginator should update the pageIndex to the ACTUAL lastPage and then _emitPageEvent() there.

What is the current behavior?

When I am on the last Page of a table and then delete the element(s) that are currently showing, the paginator will simply show a empty table with a label like "91 - 100 of 90".
Also: I am using an Array as Datasource for my Table.

What are the steps to reproduce?

The example in the Documentations shows the behavior very well (but if necessary I can still provide the stackblitz with a table)
https://material.angular.io/components/paginator/examples

Steps
#1 Click 9x on the "nextPage" Button until you are on the last Page (91-100 of 100)
#2 Click on the input "List length" and enter "90"
-> The paginator shows "91-100 of 90" INSTEAD should show "81-90 of 90" and a PageEvent fired to the last Page

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

I had the problem with Material+Material 6, but apparently it shows as well on 7
Browser: Chrome
OS: Win 10

Is there anything else we should know?

Inside the Paginator Component: The setter function for the length property could simply test if (Math.floor(value, this.pageSize) < this.pageIndex) { /* set pageIndex and emitPageEvent accordingly */}

@crisbeto crisbeto self-assigned this Dec 24, 2018
@crisbeto crisbeto added has pr P4 A relatively minor issue that is not relevant to core functions labels Dec 24, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Dec 24, 2018
Updates the page index of a paginator if its length changed to something where the index isn't valid anymore (e.g. the user is on the last page and the amount of pages becomes smaller).

Fixes angular#14520.
crisbeto added a commit to crisbeto/material2 that referenced this issue Dec 24, 2018
Updates the page index of a paginator if its length changed to something where the index isn't valid anymore (e.g. the user is on the last page and the amount of pages becomes smaller).

Fixes angular#14520.
@sebitsi
Copy link

sebitsi commented Jun 13, 2019

Hi is there any news about this bug ?
PR is still waiting... From December ? Why ?

This is bad experience for our users ! If we for example apply filter on query and less data is returned
page index is not correct.

Is there any workaround ?

crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 3, 2019
Updates the page index of a paginator if its length changed to something where the index isn't valid anymore (e.g. the user is on the last page and the amount of pages becomes smaller).

Fixes angular#14520.
@karlhaas
Copy link

karlhaas commented Jul 5, 2019

Experiencing a similar behavior: when filtering the data of the DataSource, the page index of the paginator automatically updates to the correct value. eg. 0 if the table is empty. The paginator in this case does not emit a PageEvent.
How can we persist the state of the paginator in this case? (currently we listen to PageEvent in order to store the pagination state in the url)

crisbeto added a commit to crisbeto/material2 that referenced this issue Feb 9, 2020
Updates the page index of a paginator if its length changed to something where the index isn't valid anymore (e.g. the user is on the last page and the amount of pages becomes smaller).

Fixes angular#14520.
@richieteh94
Copy link

richieteh94 commented Jan 26, 2021

Any update about this BUG?
I'm facing the same issue, after I filter in MatTable there is no page event called to the MatPaginator. I tried to implement a custom directive to read the Input changes with ngOnChanges not working as well.

@thw0rted
Copy link

thw0rted commented Aug 6, 2021

Hi @andrewseguin @crisbeto , it looks like there is a PR to fix this that's nearing its third birthday.

It seems to have stalled because there are two related properties (length and pageIndex), and when one Input forces another to change you wind up with check-after-change conflicts or a race condition. Do other components have this issue? Is there a pattern commonly used to solve this problem? I think when it happened to me, I had to make one private method that takes both values as an argument, corrects any conflicts, and applies the corrected values (once) on the next tick.

Maybe I can take a crack at getting it un-stuck and moving forward?

@thw0rted
Copy link

thw0rted commented Aug 6, 2021

Also I just found #5812 (ETA: and #17628) which says that the (IMHO objectively wrong) behavior of leaving you on page "90-100 of 25" was by design. I'm hoping that this PR means that the team's position has changed and automatically selecting the last remaining page on length change is now considered a desirable behavior?

crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 23, 2021
…ange

Updates the page index of a paginator if its length changed to something where the index isn't valid anymore (e.g. the user is on the last page and the amount of pages becomes smaller).

Fixes angular#14520.
@mmalerba mmalerba removed the has pr label Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/paginator P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants