[Paginator] Does not emit event when changed programatically
- 主要语言
- TypeScript
- 星标
- 25k
- 派生
- 6.8k
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 91
描述
#### 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 a `page` 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](https://embed.plnkr.co/dPr77Z/). 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](https://github.com/angular/material2/blob/master/src/lib/paginator/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 call
this.paginator._changePageSize(this.paginator.pageSize);
to 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.
贡献指南
调研方向
从 src/lib/paginator/paginator.ts 开始,该文件会在切换到下一页和上一页时发出 page event,并使用链接的 Plunker 重现此问题。跟踪 pageIndex setter 及相关的 paginator 行为;完成的标准是,以编程方式更改页面时会发出 page event,从而使使用方表格的结果得到一致更新。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, typescript
- 领域
- frontend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100