Angular6-Angular Mat-pagintor is not working

Viewed 20

I am using Angular 6, My input for this file is cpDataSource it contains 1000 elements, can some one help me to understand why it is not working, Thanks in advance.

HTML

<div class=" col-xs-12 col-sm-12 col-md-12" *ngIf="cpDataSource">
  <table mat-table [dataSource]="cpDataSource"  multiTemplateDataRows class="mat-elevation-z2" cellspacing="40">
  <ng-container matColumnDef="Lastname">
      <th mat-header-cell *matHeaderCellDef>
        <b>Last Name</b>
      </th>
      <td mat-cell *matCellDef="let element">
        <tr>{{element.lastName}} </tr>
      </td>
    </ng-container>
  </table>
  <mat-paginator #MatPaginator [pageSizeOptions]="[10, 20]" [pageSize]="10" showFirstLastButtons></mat-paginator>
</div>



.TS
export class TableSearchComponent implements OnInit, AfterViewInit {

  
  @Input()
  cpDataSource: ApplicationSearchResult[];
  @ViewChild(MatPaginator) paginator: MatPaginator;
   dataSource :MatTableDataSource<any>;
    ngOnInit() {
 }
  ngAfterViewInit(){
    this.dataSource = new MatTableDataSource(this.cpDataSource);
    this.dataSource.paginator = this.paginator;
  }
  }
0 Answers
Related