我在 Angular Material Table 中遇到问题,虽然它在技术上是正确的,但我在考虑是否有其他解决方法。
假设我有 5 个代码,F1
、F2
、F5
、F9
、F10
.
Angular Material Table 的升序排序是,
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>
有没有办法做到这一点?
相关链接:
最佳答案
这不是解决此问题的最佳解决方案,但我为此创建了一个简短而有效的解决方法。使用数组
的sort
谓词函数。
// Following the example to the question
financingPurposeList.sort(function(a, b){
return a.code.length - b.code.length;
});
关于Angular Material Table 字母数字排序行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55016642/