<
kendo-grid
[kendoGridGroupBinding]="data"
[sortable]="{allowUnsort : false, mode : 'single'}"
[sort]="sort"
(sortChange)="sortChange($event)">
sortChange(sort: SortDescriptor[]): void {
const sortField = sort[0].field;
const sortOrder = [
"car"
,
"boat"
,
"aircraft"
];
const sortDir = sort[0].dir;
const ordering = {};
for
(let i = 0; i < sortOrder.length; i++) {
ordering[sortOrder[i]] = i;
}
let sorted =
this
.data.sort((a, b) => {
return
(ordering[b[sortField]] - ordering[a[sortField]]);
});
if
(sortDir ===
'desc'
){
sorted = sorted.reverse();
}
this
.gridData = sorted;
}
im trying to sort the grid by custom order but when i set the 'sort' variable it ignores my function
Have you looked kendo data operations at https://www.telerik.com/kendo-angular-ui/components/data-query/bulk-operations/ for sorting? Using process, you can just pass in the sort descriptor array instead of your own code to sort the array. If you just want the grid to show what is sorted, you need to set the descriptors correctly to match your custom sort code.