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

Sort columns by descending first

1 Answer 191 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Inger Marie
Top achievements
Rank 1
Inger Marie asked on 02 Jun 2015, 11:10 AM

I have a RadGridView with a default sort-order.

When the user clicks on some of the columns, I want the default ascending sort order as the first sort order selected (as it is out of the box).

But for other columns, the user almost always wants them selected descending. This means that right now the user needs to click the column header two times (or more, if they system is a bit slow and they happen to click multiple times in anger).

That is, for a few column I would like to have:

* descending -> ascending -> none

instead of:

* ascending -> descending -> none.

I know that I can make a propery on the viewmodel which returns (Int32.MaxValue - myvalue) and use SortMemberPath, but then the arrow on the header would point in the wrong direction (it would tell the user ascending but the data would be sorted descending).

 

 Is there any way to tell individual columns, that I want the first selected sort order to be descending?

 

Thanks,

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 02 Jun 2015, 12:35 PM
Hi,

You can achieve your goal with handling RadGridView.Sorting event. To do so, please consider the following option:
- mark all the columns you wish to modify the sorting order for, for example with column.Tag="desc"
- if the user is sorting such column, then cancel the default behavior and implement the expected one
For example:

private void clubsGrid_Sorting(object sender, GridViewSortingEventArgs e)
{
    if (e.Column.Tag.ToString() == "desc" && e.OldSortingState == SortingState.None)
    {
        e.Cancel = true;
        ColumnSortDescriptor desc = new ColumnSortDescriptor();
        desc.Column = e.Column;
        desc.SortDirection = System.ComponentModel.ListSortDirection.Descending;
        (sender as RadGridView).SortDescriptors.Add(desc);
    }
}

You can also refer to the documentation on: Custom Sorting.

Regards,
Dimitrina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Inger Marie
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or