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

bug(MatPaginator): Page event fires too late. #25865

Open
1 task
Vallith opened this issue Oct 26, 2022 · 0 comments
Open
1 task

bug(MatPaginator): Page event fires too late. #25865

Vallith opened this issue Oct 26, 2022 · 0 comments
Labels
area: material/paginator P4 A relatively minor issue that is not relevant to core functions

Comments

@Vallith
Copy link

Vallith commented Oct 26, 2022

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

So when using a MatPaginator, there is an event you can bind to in order to tell when the page event has been clicked. However inside the source code (paginator.ts), that event is emitted at the end of the function:

_changePageSize(pageSize: number) {
    // Current page needs to be updated to reflect the new page size. Navigate to the page
    // containing the previous page's first item.
    const startIndex = this.pageIndex * this.pageSize;
    const previousPageIndex = this.pageIndex;

    this.pageIndex = Math.floor(startIndex / pageSize) || 0;
    this.pageSize = pageSize;
    this._emitPageEvent(previousPageIndex);
  }

This means that when using this page event you cannot do anything BEFORE the loading starts. I'm developing an app that uses rather large tables, and I want to be able to display a loading icon before the table starts updating so the app doesn't just hang. But when I show my loading icon in the (page) event, it only displays AFTER the table has finished updating and hangs for a long time. I've spent many hours trying to find a work around for this and haven't been able to figure anything out. Perhaps there is a reason as to why the line this._emitPageEvent(previousPageIndex); is here, but to my very amateurish eyes I feel like this could be solved by moving that line to the top.

Apologies in advance if this post doesn't follow the etiquette, I've not made many of these so I'm still learning.

Reproduction

Steps to reproduce:

  1. Have a table with a very long dataset
  2. Add a paginator
  3. Bind the page event on the paginator
  4. Have the page event do literally anything, let's say just write some text to the console
  5. Change the page size on the paginator from the default 50 to the full table's length
  6. Watch the console to see the app will hang until it finishes loading and only THEN do you see the text appear in the console.

Expected Behavior

I'd expect the page event to be fired first.

Actual Behavior

The page event is fired after.

Environment

  • Angular: 14.1.0
  • CDK/Material: 14.1.0
  • Browser(s): Edge
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows
@Vallith Vallith added the needs triage This issue needs to be triaged by the team label Oct 26, 2022
@zarend zarend added P4 A relatively minor issue that is not relevant to core functions area: material/paginator and removed needs triage This issue needs to be triaged by the team labels Oct 27, 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

No branches or pull requests

2 participants