【发布时间】:2019-07-27 17:41:22
【问题描述】:
我在 Angular Material Table 中遇到问题,虽然它在技术上是正确的,但我正在考虑是否有其他解决方法。
假设我确实有 5 个代码,F1、F2、F5、F9、F10。
Angular 材质表的升序排序将是,
F1
F10
F2
F5
F9
但我期待它是
F1
F2
F5
F9
F10
我的html代码在这里
<table mat-table [dataSource]="model.financingPurposeList" class="mat-elevation-z8" width="100%">
<ng-container matColumnDef="code">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Code </th>
<td mat-cell *matCellDef="let financingPurpose"> {{financingPurpose.code}} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef> Description </th>
<td mat-cell *matCellDef="let financingPurpose"> {{financingPurpose.description}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="['code', 'description']; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: ['code', 'description'];" (click)="model.selectedFinancingPurpose.toggle(row)"></tr>
</table>
有没有办法做到这一点?
相关链接:
【问题讨论】:
-
您应该在您的数据源(sortingDataAccessor)上实现自定义排序。对于自然顺序,您可能需要实现自定义算法。
标签: angular sorting angular-material