小编Der*_* J.的帖子

在同一组件中使用MatSort的多个mat-table

我在同一组件中有2个材料2个表,并进行排序.我找不到将MatSort指令分配给自己的表的方法.我只能在第一个表上使用MatSort,而第二个表不能识别它上面有MatSort.有谁知道如何配置两个表在同一组件中排序?

我尝试使用不同的名称定义ViewChild,但它不起作用.

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


this.hBSource = new HBDataSource(this.hBDatabase, this.hBPaginator, 
this.hBSort);
this.sBSource = new SBDataSource(this.sBDatabase, this.sBPaginator, 
this.sBSort);

Table 1
const displayDataChanges = [
   this.hBPaginator.page,
   this.hBSort.sortChange,
   this._filterChange
];

Table 2
const displayDataChanges = [
   this.sBPaginator.page,
   this.sBSort.sortChange,
   this._filterChange
];

Table 1
<mat-table #hBtable [dataSource]="hBSource" matSort style="min-width: 
740px;">
    <ng-container matColumnDef="domain">
        <mat-header-cell *matHeaderCellDef mat-sort-header> {{'list.domain' | translate}} </mat-header-cell>
        <mat-cell *matCellDef="let row"> {{row.domain}} </mat-cell>
    </ng-container>
    <ng-container matColumnDef="general">
        <mat-header-cell *matHeaderCellDef mat-sort-header> {{'list.general' | translate}} </mat-header-cell>
        <mat-cell *matCellDef="let row"> {{row.general.gNum}} ({{row.general.gPct | number: '1.1-2'}}%) …
Run Code Online (Sandbox Code Playgroud)

angular-material2 angular

36
推荐指数
5
解决办法
2万
查看次数

标签 统计

angular ×1

angular-material2 ×1