Argument of type 'MatTableDataSource<EmpElement>' is not assignable to parameter of type 'Collection<unknown>'.

1.2k Views Asked by At

I am facing this issue if i am adding ngx-paginator to mat table. Please help me out.

   <table mat-table [dataSource]="dataSource| paginate: {itemsPerPage: size, currentPage: p, 
   totalItems: EMP_DATA.length}" class="mat-elevation-z8" matSort>
        
    .
    .
    <pagination-controls (pageChange)="p = $event;paginate(p)"


    [responsive]="true"
    ></pagination-controls>

IN ts file

         size = 10;
         pageIndex = 0;
         p=1;
         dataSource = new MatTableDataSource<EmpElement>(this.EMP_DATA);

          paginate(event: any) {
          this.pageIndex=event;
            }
1

There are 1 best solutions below

4
On

From the error, I am assuming that EmpElement is not an array

Change below line :

 dataSource = new MatTableDataSource<EmpElement[]>(this.EMP_DATA);