Default sort direction in the grid

1 Answer 2953 Views
General Discussions
Yuriy
Top achievements
Rank 1
Yuriy asked on 08 Feb 2018, 11:32 PM

Hi,

 

is it possible to change default starting sort direction of Grid from ASC to DESC?

Thanks,

Yuriy 

Dimiter Topalov
Telerik team
commented on 09 Feb 2018, 09:20 AM

Hello Yuriy,

You can specify the default initial sorting direction (and field the data will be sorted by) of the Grid by binding the "sort" input to the desired array of Sort descriptors, e.g.:

https://plnkr.co/edit/ViZf3yKbe4NdQ876dST0?p=preview

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Yuriy
Top achievements
Rank 1
commented on 09 Feb 2018, 02:10 PM

Hi Dimiter,

Thanks for the quick reply. 
It's not exactly what I want. My task: 
1. Grid's initial load is without any sorting

2. When user initiates sorting from any column header the direction is DESC

Thanks,

Yuriy

 

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 12 Feb 2018, 11:41 AM
Hello Yuriy,

Thank you for the clarification about the desired behavior. The only way to achieve it via the built-in Grid sorting functionality (i.e. via modifying the Sort descriptors, based on some custom logic) would be to sacrifice the allow unsort functionality (i.e. once the Grid is sorted by some field, further sorting will yield either ascending or descending direction, not "unsorted" or the initial state), e.g.:

https://plnkr.co/edit/w4COEPeGhuU5CsOoHN0m?p=preview

This is due to the fact that the default sorting direction "cycle" of the Grid is (starting from an initial unsorted state): 'asc' --> 'desc' --> 'unsorted' --> 'asc'...

There is no reliable way to both switch the direction to 'desc' when it is 'asc' and vice versa, because the incoming descriptor after the direction is switched to 'desc' will contain 'undefined' for the direction (if the default allow unsort functionality is enabled) and the next value will be 'asc'... but we are programmatically switching 'asc' to 'desc', so 'desc' will never arrive as a sort descriptor info in the sortChange event and thus we are unable to switch it to 'asc'. This is why if we need to reverse the built-in Grid sorting order, we will have to sacrifice the allow unsort functionality. I hope this makes sense.

That said, if you have the time, please submit a feature request to our UserVoice portal for any features and enhancements (like the desired customized Grid sorting functionality) that you would like to see as a built-in configurable feature in a future version of our packages:

http://kendoui-feedback.telerik.com/forums/555517-kendo-ui-for-angular-feedback?category_id=181393

This will help us estimate the customer demand for certain features, and prioritize accordingly when updating our roadmap. Thank you in advance.

Regards,
Dimiter Topalov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Yuriy
Top achievements
Rank 1
commented on 12 Feb 2018, 02:33 PM

Thank you!
Tags
General Discussions
Asked by
Yuriy
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Share this question
or