Multiple mat-table with MatSort within the same component

后端 未结 5 1454
一向
一向 2020-12-15 15:01

I have 2 material 2 tables in the same component with sorting. I cannot find a way to assign the MatSort directive to its own table. I\'m only able to use MatSort on the fir

5条回答
  •  囚心锁ツ
    2020-12-15 15:39

    Edit:

    I believe you need:

    @ViewChild(MatSort) sort: MatSort;
    

    above your:

    @ViewChild('hBSort') hBSort: MatSort;
    @ViewChild('sBSort') sBSort: MatSort;
    

    Then:

    ngAfterViewInit() {
        this.hBSource.sort = this.sort;
        this.sBSource.sort = this.sort;
      }
    

    Assuming that your HBDataSource and SBDataSource both export MatTableDataSource();

    I'm referencing these sources:

    https://material.angular.io/components/sort/overview https://github.com/angular/material2/blob/master/src/demo-app/table/table-demo.ts

提交回复
热议问题