Sort columns by descending first

2 posts, 0 answers
  1. Inger Marie
    Inger Marie avatar
    86 posts
    Member since:
    Nov 2010

    Posted 02 Jun 2015 Link to this post

    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?



  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 02 Jun 2015 Link to this post


    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.

    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
Back to Top