This is a migrated thread and some comments may be shown as answers.

Custom sort

0 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
yair
Top achievements
Rank 1
yair asked on 01 Feb 2021, 01:02 PM
<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

Paul
Top achievements
Rank 2
Iron
Veteran
Iron
commented on 13 Jul 2021, 05:20 PM

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.

No answers yet. Maybe you can help?

Tags
Grid
Asked by
yair
Top achievements
Rank 1
Share this question
or