[英]Angular dynamic data sorting table
Im having a hard time on how to do a sorting with dynamic data in my table, the [dataSource]="dataSource" is my DTO or Model wherein I get the field that I needed.我很难对表中的动态数据进行排序,[dataSource]="dataSource" 是我的 DTO 或 Model,其中我得到了我需要的字段。 I dont know how to implement the sorting in my code.
我不知道如何在我的代码中实现排序。 I can't do on my ts:dataSource = new MatTableDataSource because I already used it as my Model.
我不能在我的 ts:dataSource = new MatTableDataSource 上做,因为我已经将它用作我的 Model。 Help please I dont know this one T_T
求帮助 我不知道这个T_T
.html .html
<mat-table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="classification">
<mat-header-cell *matHeaderCellDef mat-sort-header> Classification </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.groupClassificationDTO.classificationDTO.nameClassification}} </mat-cell>
</ng-container>
<ng-container matColumnDef="subClassification">
<mat-header-cell *matHeaderCellDef mat-sort-header> Sub-Classification </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.groupClassificationDTO.subClassificationDTO.nameSubClassification}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
ts. ts。
dataSource: ChartofAccountsDTO[] = [];
@ViewChild(MatSort, {static: true}) sort: MatSort;
Try a setter along with MatTableDataSource尝试使用 setter 和 MatTableDataSource
dataSource: MatTableDataSource<ChartofAccountsDTO> = new MatTableDataSource();
@ViewChild(MatSort)
set matSort(sort: MatSort) {
this.dataSource.sort = sort;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.