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

sort in descending order

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryann
Top achievements
Rank 1
Ryann asked on 04 Dec 2013, 01:38 PM
hi.
I want the sorting to sort in descending order first rather than ascending which is the default behaviour.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Dec 2013, 01:44 PM
Hi Ryann,

Please try the following code snippet to have sorting in descending order at first.

C#:
protected void RadGrid1_SortCommand(object sender, GridSortCommandEventArgs e)
{
    GridSortExpression sortExpr = new GridSortExpression();
    switch (e.OldSortOrder)
    {
        case GridSortOrder.None:
            sortExpr.FieldName = e.SortExpression;
            sortExpr.SortOrder = GridSortOrder.Descending;
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
            break;
        case GridSortOrder.Ascending:
            sortExpr.FieldName = e.SortExpression;
            sortExpr.SortOrder = RadGrid1.MasterTableView.AllowNaturalSort ? GridSortOrder.None : GridSortOrder.Descending;
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
            break;
        case GridSortOrder.Descending:
            sortExpr.FieldName = e.SortExpression;
            sortExpr.SortOrder = GridSortOrder.Ascending;
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
            break;
    }
 
    e.Canceled = true;
    RadGrid1.Rebind();
 
    if (!e.Item.OwnerTableView.SortExpressions.ContainsExpression(e.SortExpression))
    {
        sortExpr.FieldName = e.SortExpression;
        sortExpr.SortOrder = GridSortOrder.Ascending;
        e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
    }
}

Thanks,
Princy
Tags
Grid
Asked by
Ryann
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or