0

I have a project with pagination options. https://stackblitz.com/edit/angular-sjp8qq

But mat-pagination tag´s properties arent tied up with an app logic. Can someone tell me why, please?

Mike Kylmä Lampi
  • 465
  • 1
  • 5
  • 15

1 Answers1

0

Below is how I got a mat-pagination to work in an application I am working adjusted to fit in with your code, hope this helps.

JS

totalElements = 20;
elementsPerPage = 5;
currentPage = 1;
pageSizeOptions = [5, 10, 20];


fillDataSource() {
 this.arraySource = []; // clear so we can repopulate
 for ( let i = 0; i < this.arraySize; i++) { 
   if (this.elementsPerPage &&  this.currentPage) {
     if (i > (this.elementsPerPage * (this.currentPage - 1)) && i <= (this.elementsPerPage * (this.currentPage))) {
      this.arraySource.push(this.arrayTemplate)
     }
   }
 }
 this.data = new MatTableDataSource(this.arraySource)
}

onChangedPage(pageData: PageEvent) {
 this.currentPage = (pageData.pageIndex + 1);
 this.projectsPerPage = pageData.pageSize;

 this.fillDataSource();
}

HTML

 <mat-paginator
  #paginator
  [length]="totalElements"
  [showFirstLastButtons]="true"
  [pageSizeOptions]="pageSizeOptions"
  [pageSize]="elementsPerPage"
  (click)="onChangedPage($event)">
 </mat-paginator>
Dylan Anlezark
  • 1,256
  • 2
  • 12
  • 27
  • Dylan, it works, but I didnt get how .. I mean, the important part is where you changed a **fillDataSource()** method, but when I am trying just to attach to data source - it doesnt work .. Can you please see the updated code here? https://stackblitz.com/edit/angular-sjp8qq – Mike Kylmä Lampi Jun 25 '19 at 23:07
  • I'm sorry I can't be of more help my knowledge about mat-paginator really is limited to what i have shared in my answear. – Dylan Anlezark Jun 25 '19 at 23:25
  • Can you please just superficially look for the last changes ..? In the stackblits – Mike Kylmä Lampi Jun 25 '19 at 23:27