tags:

views:

27

answers:

2

Is there a way to specify the default sorting direction for columns in a Telerik MVC Grid?

example: click on column 'Date' and it sorts descending, click on column 'Name' and it sorts ascending

A: 

I suppose you can play with the OrderBy method of the Telerik MVC grid and define the sort order explicitly - at least this is what I see from the demo description here.

Dick

Dick Lampard
That lets you set the initial sort on the table only.
Harry
I think that this may somehow be coupled with the action method (_Sorting) and the ViewData params to specify the sort order dynamically.
Dick Lampard
A: 

I do not think there is a way in today's Grid to change the "cycle" order for sorting operations. By default, the Grid will cycle through these sort orders when the header is clicked:

Unsorted > Ascending > Descending

If you use the API options described by Dick, you can set the initial sort behavior, but once the column is clicked, it will "resume" the cycle. So, if you set Date to Ascending initially, the next click will sort by Descending.

This is relatively common behavior for web grids, so it meets user experience expectations.

If you want to take explicit control over sorting behavior, there is a rich client-side API that allows you to specify sort and filters directly:

var grid = $('#yourGridId').data('tGrid');
//Descendingly sort the records by the Name property
grid.filter('Name-desc');

As you can see, you can specify the property name and sort direction. You can also sort on multiple fields. See the online docs for more examples.

Todd
will changing the sort in javascript correctly update the sort direction indicator image?
Harry