-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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] Does not emit event when changed programatically #8417
Comments
I meant to leave a trackback to #6220 in the original issue -- not exactly the same thing, but related. |
page
event when assigning to pageIndex
Came here with the same problem. I needed a way to keep paginator on the same page after a data update for a mattable. The pageSize hack from @thw0rted is still the best option. For others using paginator with mattable, I had to set the pageIndex inside a timeout in order for paginator to detect that the pageIndex was changed: @ViewChild(MatPaginator) paginator: MatPaginator;
public dataSource: MatTableDataSource<{ [id: string]: any }>;
...
refreshPaginator() {
if (!this.dataSource.paginator) {
this.dataSource.paginator = this.paginator;
}
let pageIndex = 0;
... // some math
setTimeout((idx) => {
this.paginator._pageIndex = idx;
this.paginator._changePageSize(this.paginator.pageSize);
}, 0, pageIndex);
} |
I had to add this.paginator._changePageSize(this.paginator.pageSize); to get mine working also |
It says : "Property '_pageIndex' is private and only accessible within class 'MatPaginator'" |
Quite some time ago, I believe they added a public accessor for |
I haven't looked at this in ages. @andrewseguin is there any debate about this? I'm pretty sure it's unambiguously a bug, and can be fixed by inserting a call to ETA: while we're at it, can we talk about why there are two different ways to change the page size ( |
Hello again as we near the 2-year anniversary of this bug! #6220 just got auto-closed so I figured I should stop by here to provide some activity and avoid the same fate. Ping! 😁 |
@thw0rted Just FYI - that bot only locks already closed issues, it doesn't close them. So open issues like this should be OK without a bump. |
Hi all any workaround on this ? |
Hello Everyone. Here is My working example.
|
AshotAleqs solution works very good - without flickering (as with setTimeout). Little improvement:
|
@b-mi ah I see, Thank you. I forgot to change my properties |
will this ever be fixed? :) |
What version is used where emitting the page event or using the public |
Hello, @alexpearce92 I have used a 7.2 version of angular. And the solution works correctly. without any errors |
Only works on my end with the setTimeout |
Using Ran into this again. Taking a look at the source, fairly confident that the problem is the fact that no Pretty sure where it is currently:
It needs to be more like this:
I haven't seen any reason mentioned as to why we would explicitly NOT want to emit the PageEvent from the setter; The latter of which seemed to fix a problem with the change detection, however, this issue is distinctly different from the change detection. When you set the For quick fix: In my Component I get a reference to the paginator like so: Then in my
Then you can use the assignment operator as expected, like so:
|
Update 2022: Tried both @alexpearce92 and @AshotAleqs workaround, however only @alexpearce92 's worked for me. |
Update 2023: I am still having the same issue. I can set `
` Only workaround that works me is setTimeout or delay pipe With above code changes only pageSize |
@celalettin-turgut This behavior is seemingly intentional and a "fix" would break existing workflows. If you want to navigate programmatically, you should use the |
The original issue is about going directly to a page, not first/last or increment/decrement. Is there a method for jumping to a specific page? |
@thw0rted Perhaps this link can help you: https://stackoverflow.com/a/51552039 |
Hello All, |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
Changing the page index programmatically should emit a
page
event.What is the current behavior?
Assigning to
.pageIndex
does not emit apage
event. There is no method to jump to a specified page and ensure that an event is emitted.What are the steps to reproduce?
Open this plunker. Enter a (different) page number in the input at the top of the page and click "Go To". The displayed paginator offset ("11-20") changes but the table results do not.
What is the use-case or motivation for changing an existing behavior?
The current behavior is wrong. The documentation for the
page
Output says "Event emitted when the paginator changes the page size or page index"; the page index has changed but the event was not emitted.Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Still happening as of Beta 12, at least.
Is there anything else we should know?
I checked paginator.ts and the event is emitted in various methods that change the page index (next / previous) but not in the setting for pageIndex itself. I don't know why this design decision was made so I hesitate to suggest that it be changed, but we need some way to tell the paginator to go to a page as though the user had clicked to get to that page.
In the short term, I noticed that the private method
_changePageSize
is exposed in the typings for this component, and does not check if the size being set is the current size. So I can callto force the paginator to emit a
page
event. Of course it's a pretty awful hack, but it gets the intended behavior. It'd be nice to avoid this in a future release.The text was updated successfully, but these errors were encountered: