Home > Mobile >  (ANGULAR-12) Mat-paginator change page after condition
(ANGULAR-12) Mat-paginator change page after condition

Time:11-10

I'm looking for the way to change the page of the mat-paginator inside of my HTML.

When i edit a user, i want to stay on the same page of the mat-paginator. So i store this information inside the currentPage variable.

But i want to say to angular, if this variable !null, go to this page of mat-paginator


<mat-paginator *ngIf="!currentPage" color="primary" [hidden]="dataSource.totalItems === 0" [length]="dataSource.totalItems" [pageSize]="dataSource.pageSize" [pageIndex]="dataSource.pageIndex - 1" [pageSizeOptions]="pageSizeOptions" (page)="onPaginateChange($event)" showFirstLastButtons>


thank you very much.

i tried to write two but i can't re-render an pagination without an event.

CodePudding user response:

this.paginator.pageIndex = this.goTo - 1;
   const event: PageEvent = {
   length: this.paginator.length,
   pageIndex: this.paginator.pageIndex,
   pageSize: this.paginator.pageSize
};
this.paginator.page.next(event); 

here goTo is variable which indicate on which page you want to go so after saving the information of user you need to put above code to navigate to page.

  • Related