0

I'm looking for a 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 as 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

<!-- Pagination -->
<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>
</mat-paginator>

thank you very much.

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

Mr. Stash
  • 2,940
  • 3
  • 10
  • 24
Mehdy093
  • 3
  • 2
  • what kind of error occurs ? can you please give us code of block that demonstrate detail information – Parth M. Dave Nov 10 '22 at 09:06
  • Hello, no error occurs i am just looking for the way to do this. – Mehdy093 Nov 10 '22 at 09:09
  • as per my understanding you have mat-table with information of user & you trying to edit one of the from table & after save the record you want to stay on same page as currently user information have right? – Parth M. Dave Nov 10 '22 at 09:22
  • @ParthM.Dave Exactly, the editing works, but i want to stay on the same page (of mat-paginator) – Mehdy093 Nov 10 '22 at 09:27

1 Answers1

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

Parth M. Dave
  • 853
  • 1
  • 5
  • 16