我在尝试manuallky触发器对ngx-datatable中的行进行排序时遇到了一些问题。 场景是在小型设备上我将一些列从标题移动到ngx-datatable-row-detail,但是当我尝试调用customSort函数时,ngx-datatable中的行没有被排序为我期待。
模板如下所示:
<ngx-datatable #myTable [columnMode]="'flex'"
[rows]="_appointments"
[rowHeight]="'auto'"
[sorts]="listProps.currentSort"
(sort)="sorted($event)"
[columns]="_tableColumns">
<ngx-datatable-row-detail [rowHeight]="'auto'" #myDetailRow>
<ng-template let-row="row" let-expanded="expanded" ngx-datatable-row-detail-template>
<div class="ngx-table-toogle hidden-md">
<div [class.visible-xs]="myCol.collapse_xs" [class.visible-sm]="myCol.collapse_sm" *ngFor="let myCol of _collapsedTableColumns">
<div class="col-xs-12 col-sm-4" [class.sortable]="myCol.sortable" (click)="onCustomSort(myCol.prop,myCol.sortable)">
<div class="detail-row-header">
{{myCol.name}}
<span [class.sort-btn]="myCol.sortable" [class.sort-desc]="isSortedBy(myCol.prop,'desc')" [class.sort-asc]="isSortedBy(myCol.prop,'asc')"></span>
</div>
</div>
<div class="col-xs-12 col-sm-8">
<span class="detail-row-data">{{getVal(row,myCol.prop)}}</span>
</div>
</div>
</div>
</ng-template>
</ngx-datatable-row-detail>
onCustomSort方法如:
onCustomSort(sortCol: string, sortable:boolean) {
if (!sortable)
return;
let curdir = this.listProps.currentSort[0].dir === SortDirection.desc ? SortDirection.asc : SortDirection.desc;
// Hmm, doesn't trigger a resorting of the table.
this.listProps.currentSort = [{ prop: sortCol, dir: curdir }];
this.table.sorts = this.listProps.currentSort;
}
我希望修改this.listProps.currentSort
会触发表格,因为它绑定到[sorts]="listProps.currentSort"
但没有任何反应。
有什么想法吗?
答案 0 :(得分:0)
实际上解决方案非常简单,只需要添加
this.table.onColumnSort({ sorts: this.listProps.currentSort });
到onCustomSort方法,所以它现在看起来像这样:
onCustomSort(sortCol: string, sortable:boolean) {
if (!sortable)
return;
let curdir = this.listProps.currentSort[0].dir === SortDirection.desc ? SortDirection.asc : SortDirection.desc;
this.listProps.currentSort = [{ prop: sortCol, dir: curdir }];
this.table.onColumnSort({ sorts: this.listProps.currentSort });
}