Мне нужно добавить сортировку по одному полю по абсолютному значению значения. Это мой компонент:
<kendo-grid [kendoGridBinding]="gridData | async"
[filterable]="true"
[pageSize]="10"
[pageable]="true"
[sortable]="true"
[height]="410">
<kendo-grid-column *ngFor="let col of columns"
[field]="col.field"
[title]="col.title"
[filterable]="col.filter"
[filter]="col.type"
[format]="col.format"
[sortable]="col.sortable"
></kendo-grid-column>
</kendo-grid>
Это мой класс компонента:
export class GridComponent implements OnInit {
gridData: any;
columns = [
{ filter: true, title: 'Name', field: 'name', type: 'text' },
{ filter: true, title: 'Date', field: 'date', type: 'date', format: '{0:MM/dd/yyyy}' },
{ filter: true, title: 'Amount', field: 'amount', type: 'numeric' , sortable: true},
{ filter: true, title: 'Currency', field: 'currency'}
];
constructor(private dataService: DataService) { }
ngOnInit() {
this.preloadData();
}
private preloadData() {
this.gridData = this.dataService.getData();
}
}
Я попытался добавить вместо сортируемого: true это:
sortable: {compare: function(a,b) { return Math.abs(a) > Math.abs(b)} }
Однако этоговорит мне, что эта функция ожидает возврата логического значения. Итак, есть ли способ, как реализовать свой собственный компаратор?