Custom sort function in kendo react grid

1 Answer 67 Views
Grid Sortable
samir
Top achievements
Rank 1
samir asked on 26 Dec 2022, 07:37 AM
i found many example using compare function in sortable options in js or jquery kendo grid. How can i achieve thing using kendo react grid ?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 26 Dec 2022, 08:43 AM

Hi Samir,

Thank you for reaching out to us.

The "orderBy" and the "process" helper methods provided by the data query package work with SortDescriptors and they do not allow passing custom comparer function. If you want to implement custom sorting and since the sorting should be the first data operation if paging is enabled, what I could suggest is to handle the sorting manually, remove the sort expression from the DataState (if you are using the process helper method) and only then proceed with the other operations. You will have something like the following:

let sortExpressions = myDataState.sort;
let stateWithoutSorting = {...myDataState, sort: []}; //here you will remove the sort expressions from the DataState
let sortedData = handleSorting(myData, sortExpressions); //here you will apply the sorting
setData(process(sortedData, stateWithoutSorting)

Hope this helps. 

 

Regards,
Konstantin Dikov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid Sortable
Asked by
samir
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or