angular / angular/components

[Paginator] Does not emit event when changed programatically

Ouverte
#8,417 23 commentaires 26 réactions 0 personnes assignées Voir sur GitHub
area: material/paginator P3
Langage dominant
TypeScript
Étoiles
25k
Forks
6.8k
Merge moyen
1 j 8 h
PR mergées (30 j)
91

Description

#### 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.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par src/lib/paginator/paginator.ts, où le page event est émis lors des changements vers les pages suivante et précédente, et reproduisez le problème à l’aide du Plunker lié. Suivez le pageIndex setter et le comportement associé du paginator ; le travail sera terminé lorsque les changements de page programmatiques émettront le page event afin que les résultats de la table consommatrice soient mis à jour de manière cohérente.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
angular, typescript
Domaine
frontend
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
42/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.