Is it possible to apply custom sort logic to a Data Grid Column

1 Answer 431 Views
Grid Sortable
David
Top achievements
Rank 1
Iron
Iron
Veteran
David asked on 03 May 2023, 01:38 PM

Hi,

Is it possible to apply custom sort logic to a Data Grid Column which is applied when clicking on the Column header? As an example, we have a Date column with nullable values. We would like nulls to be considered highest i.e.

  • ascending: lowest date value -> highest date value -> null date values
  • descending: null date values -> highest date value -> lowest date value

In the default sort nulls are considered lowest.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 04 May 2023, 05:22 PM

Hello David,

Currently the helper methods that we provide do not allow custom sorting function. We have logged issue for this, but at this point we could not elaborate when it will be available:

With the current implementation, the only possible solution would be to handle the data operations manually, using the sort expressions provided by the Grid and pass the data to the Grid's "data" property after applying the custom sorting. 

 

Regards,
Konstantin Dikov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources!

David
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 04 May 2023, 11:59 PM

OK, so you're saying we can sort the data manually but if the user clicks the column heading then that manual sort will be lost?

Kind regards,

David

Konstantin Dikov
Telerik team
commented on 08 May 2023, 08:42 AM

Hi David,

Clicking on the Grid's header will change the sort expression passed to the onDataStateChange (onSortChange) event and nothing more. The Grid component does not have internal logic for applying data operations and in our examples we are using helper methods (like process, orderBy, etc.) that can use the expressions from the Grid's events. What I have suggested was to use a different method for applying the data operations based on the sort expressions. 

David
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 08 May 2023, 09:56 AM

Thanks Konstantin,

Is it possible to provide an example of the solution you have proposed?

Kind regards,

David

Konstantin Dikov
Telerik team
commented on 09 May 2023, 01:02 PM

Hi David,

I have created a simple example demonstrating how you can create a custom process method where you can handle all data operations manually:

The example handles the paging and sorting over single field, but you can extend it to include filtering and multi field support as per your exact requirements.

As you will notice, I have added custom sort compare function and you can extend it and add custom logic for particular fields.

Hope this helps.

 

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