A paginator itself give you an index from 0 to number of pages. The only thing you need is change the displayColumns taking account this index.
If you has, e.g. a paginator like
<mat-paginator #paginator [length]="7" hidePageSize="true"
(page)="changeDisplayColumns($event)"
[pageSize]="2">
</mat-paginator>
and a variable with all the columns
displayedColumnsAll: string[] = ['position', 'name', 'weight',
'symbol',"another","another2","another3"];
See that in [length]
of paginator you put the quantity of columns (in the e.g."7")
You can do
changeDisplayColumns(page:PageEvent)
{
this.displayedColumns=this.displayedColumnsAll.slice(
page.pageIndex*page.pageSize,
page.pageIndex*page.pageSize+page.pageSize)
}
See a fool stackblitz
NOTE: At first you need give value to displayedColums with index=0, see the
displayedColumns=this.displayedColumnsAll.slice(0,2)
in the stackblitz
allColumns
and add two buttons that will change the contents of thedisplayedColumns
for your table. You can style it similarly to the mat-paginator as well. – TotallyNewb