-
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
fix(paginator): not emitting page event when pageIndex, pageSize or length changes #12586
Conversation
src/lib/paginator/paginator.ts
Outdated
if (newPageSize !== this._pageSize) { | ||
this._pageSize = newPageSize; | ||
this._updateDisplayedPageSizeOptions(); | ||
this._emitPageEvent(this.pageIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also markForCheck?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs to since it's going through an Output
. At least in my testing it wasn't necessary.
src/lib/paginator/paginator.ts
Outdated
|
||
if (newLength !== this._length) { | ||
this._length = newLength; | ||
this._emitPageEvent(this.pageIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since alot of usages of the MatPaginator
with a DataSource
update the length whenever the data updates, this could cause a loop of sorts.
The if block would prevent it from happening more than once, but we still would be triggering the DataSource
's value multiple times.
An example can be seen here with the table-data-source
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the table user the IterableDiffer
under the hood? That should prevent it from doing extra work even if it does fire multiple times. I'm fine with cutting down the PR so it only addresses the pageSize
as mentioned in #12583, but I can imagine people running into the same issue for the other two properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just got another issue about the pageIndex
: #12620.
df92594
to
7b0531c
Compare
Something does feel weird about this change. Andrew would have a better idea, but I vaguely recall the decision for |
I suppose the difference between the |
Mind if we sit on this one for a few weeks until Andrew gets back? I'd like to chat with him about it. |
Hi @crisbeto! This PR has merge conflicts due to recent upstream merges. |
7b0531c
to
19e617f
Compare
The page index is typically set to zero in user code in response to sort changes and filter changes, which typically themselves already result in table-reloading chains of events including calls to a service or repository. (While an application-user might be half-way through a long paginated list, they are generally assumed to want to be placed at the top of the reformulated list when the sort or filter changes appear. Sort and filter changes render page position meaningless or at least ambiguous; and, by convention, sorting is seldom implemented on a paginated-page-local basis.) If MatPaginator.page fires as a result of this reset in code to the first page, a second, redundant call on the datasource would be caused under common circumstances, unless user code implements some sort of gating or temporal windowing/debouncing mechanism. Overall, this change might cause some inconvenience for alert developers, and, a subtle bandwidth and performance loss for less-alert developers. (Subtle, because it will be triggered only if the page number is not already zero at the time the filter or sort change is made; we are talking about an extra, back-end call in SPAs; and, finally, it might not jump off the page for some devs less familiar with asynchronous reactive subscription lambda syntax.) If this breaking change is to be made, then perhaps it should be mitigated by adding a new MatPaginator method that goes to the first page without triggering the MatPaginator.page event and to disseminate knowledge (e.g. in the examples) that this call should be used in lieu of For typical current user code, consider the following excerpt from the "Table retrieving data through HTTP" mat-table example in the API docs online.
(Incidentally, I found this issue when I sought to confirm that, as things stand, I would not have to intercept/block incident calls to my datasource indirectly caused by my component filtering and sort event-handling functions.) |
…than the current page Fixes the table not rendering correctly when going from a large set of data (e.g. 50 items and on page 10) to a small set of items (e.g. 1 item). The issue comes from the fact that the paginator doesn't emit events if they weren't generated by the user (see discussion on angular#12586). Fixes angular#14010.
…than the current page Fixes the table not rendering correctly when going from a large set of data (e.g. 50 items and on page 10) to a small set of items (e.g. 1 item). The issue comes from the fact that the paginator doesn't emit events if they weren't generated by the user (see discussion on angular#12586). Fixes angular#14010.
…than the current page (#14665) Fixes the table not rendering correctly when going from a large set of data (e.g. 50 items and on page 10) to a small set of items (e.g. 1 item). The issue comes from the fact that the paginator doesn't emit events if they weren't generated by the user (see discussion on #12586). Fixes #14010.
…than the current page (angular#14665) Fixes the table not rendering correctly when going from a large set of data (e.g. 50 items and on page 10) to a small set of items (e.g. 1 item). The issue comes from the fact that the paginator doesn't emit events if they weren't generated by the user (see discussion on angular#12586). Fixes angular#14010.
…than the current page (angular#14665) Fixes the table not rendering correctly when going from a large set of data (e.g. 50 items and on page 10) to a small set of items (e.g. 1 item). The issue comes from the fact that the paginator doesn't emit events if they weren't generated by the user (see discussion on angular#12586). Fixes angular#14010.
…than the current page (#14665) Fixes the table not rendering correctly when going from a large set of data (e.g. 50 items and on page 10) to a small set of items (e.g. 1 item). The issue comes from the fact that the paginator doesn't emit events if they weren't generated by the user (see discussion on #12586). Fixes #14010.
19e617f
to
4c93b61
Compare
Any updates on this? |
…ength changes Currently the paginator won't fire the `page` event if it's `pageIndex`, `length` or `pageSize` change, which means that the associated table won't be able to react. These changes emit the event if the values change. Fixes angular#12583.
4c93b61
to
c8b7edb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many of our components have a stateChanges stream that emits when inputs are changed. I think that would be better suited for this case. The MatTableDataSource could watch for changes off that stream and re-render. For users that have their own data source, they can either listen for that stream or otherwise handle what they provide to the table when these inputs are changed.
Closing per Andrew's comment above that we would prefer something like a |
Currently the paginator won't fire the
page
event if it'spageIndex
,length
orpageSize
change, which means that the associated table won't be able to react. These changes emit the event if the values change.Fixes #12583.