1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Set pageIndex in Material Paginator

Discussão em 'Angular' iniciado por mtmx, Maio 15, 2025.

  1. mtmx

    mtmx Guest

    I want to store in session storage pageIndex of my paginator, that is no problem:

    onPageChange(event: PageEvent): void {
    sessionStorage.setItem('pageIndex',String(this.paginator.pageIndex))
    }


    Problem for me is restoring this value from sessionStorage

    <mat-paginator class="centered-paginator table-content"
    aria-label="Wybierz stonę"
    app-paginator
    translate="yes"
    showFirstLastButtons
    [appCustomLength]="customLength"
    [pageSize]=10
    [pageSizeOptions] = "[5, 10, 25]"
    (page)="onPageChange($event)"
    [resultsLength] = dataSource.filteredData.length>
    </mat-paginator>


    and in .ts

    dataSource = new MatTableDataSource<any>();
    @ViewChild(MatPaginator) paginator: MatPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype);
    .....
    ngAfterViewInit() {
    this.paginator.pageIndex=5 //page on init set to 5, without sessionStorage for now
    this.dataSource.paginator = this.paginator;
    }


    I tried also

    [pageIndex]="5"


    in mat-paginator declaration in html, but after loading the table I am still on the first page. Do You know maybe what's wrong here?

    Continue reading...

Compartilhe esta Página