首页 文章

使用动态列排序 - 角度材质

提问于
浏览
0

我正在使用URL而我正在进行排序 . 排序工作正常,但我有2个数字列

  • 权重 - 其值来自DB通过API调用,它存在于dataSource中 . (这里排序正常)

  • 双重权重:其公式为:权重* 2.此处, "Double weight" 是以HTML格式动态计算的,因此在数据源中不可用 .

我需要在 "Double weight" 列中应用排序 . 有人可以指导我这个 .

HTML

<ng-container matColumnDef =“weight”>

<th mat-header-cell * matHeaderCellDef mat-sort-header> Weight

<td mat-cell * matCellDef =“let element”> {{element.weight}}

</ ng-container>

<ng-container matColumnDef =“weight2”>

<th mat-header-cell * matHeaderCellDef mat-sort-header> Weight

<td mat-cell * matCellDef =“let element”> {{element.weight * 2}}

</ ng-container>

TS

@ViewChild(MatSort) sort: MatSort;
ngOnInit() {
this.dataSource.sort = this.sort;
}

1 回答

  • 0

    我很确定 (weight * 2) 上的排序与 weight 排序的结果完全相同 .

    因此,当您在两列中显示不同的值时,只需在两种情况下对权重进行排序 .

相关问题