我在角度材质表中遇到问题,尽管它在技术上是正确的,但我在想是否有另一种方法可以解决这个问题。
假设我有 5 个代码,F1
, F2
, F5
, F9
, F10
.
角度材质表升序排列顺序将是,
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
的谓词函数array
.
// Following the example to the question
financingPurposeList.sort(function(a, b){
return a.code.length - b.code.length;
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)