1

From this SO post i learned that in order to deal with large datasets you should set dataSource.paginator before dataSource.data in ngAfterViewInit.

However when doing this I am not able to set an initial pageIndex using this.paginator.pageIndex.

https://stackblitz.com/edit/angular-mat-table-v2

When I load my data in ngOnInit and the paginator after this in ngAfterViewInit, I am able to set the initial pageIndex:

https://stackblitz.com/edit/angular-mat-table-v1

Michael Hunziker
  • 2,659
  • 3
  • 22
  • 26

1 Answers1

4

You can try this:

  ngOnInit() {
     this.dataSource.paginator = this.paginator;
  }

  ngAfterViewInit() {
    setTimeout(() => {
     this.paginator.pageIndex = 3;
     this.todos$.subscribe((todos) => this.dataSource.data = todos);
    }, 0);
  }