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

Clear SortedBackColor

7 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 24 Jul 2008, 09:40 PM
I have the following tag in my RadGrid:

<SortingSettings SortedBackColor="LightYellow" /> 

When I click on the column to sort descending or ascending the column is highlighted in LightYellow as I expected.  What do you have to do to clear the highlighted column?

Here is my SortCommand

   protected void RadGrid1_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)  
    {  
        if (!e.Item.OwnerTableView.SortExpressions.ContainsExpression(e.SortExpression))  
        {  
            // The intial page load will not have a NewSortOrder, so Ascending is set to default  
            GridSortExpression sortExpr = new GridSortExpression();  
            sortExpr.FieldName = e.SortExpression;  
            sortExpr.SortOrder = GridSortOrder.Ascending;  
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);  
        }  
        else  
        {  
            // After the initial page load we will have access to NewSortOrder  
            e.Canceled = true;  
            GridSortExpression sortExpr = new GridSortExpression();  
            sortExpr.FieldName = e.SortExpression;  
            // If NewSortOrder is still empty set it to Ascending otherwise start using NewSortOrder  
            if (String.IsNullOrEmpty(Convert.ToString(e.NewSortOrder)))  
            {  
                sortExpr.SortOrder = GridSortOrder.Ascending;  
            }  
            else  
            {  
                sortExpr.SortOrder = e.NewSortOrder;  
            }  
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);  
            RadGrid1.Rebind();  
        }  
    } 

Here is my NeedDataSource where I use ViewState to hold the data since I have a search form above the grid and need it to persist the gird.  Without it the Grid becomes empty.
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
    {  
        string gridSortString = this.RadGrid1.MasterTableView.SortExpressions.GetSortString();  
        string text = "Grid sort expression: " + gridSortString;    
        DataSourceSelectArguments args = new DataSourceSelectArguments(gridSortString);  
        RadGrid1.DataSource = ViewState["DataTable1"];  
    } 

7 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 25 Jul 2008, 12:32 PM
Hello George,

A sorted column loses its SortedBackColor as soon as it is not sorted any more (i.e. the relevant sort expression is removed). If this does not work for you, then I guess you are trying to implement some custom scenario. Could you give some details what exactly are you trying to do?

Greetings,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 25 Jul 2008, 01:27 PM
Dimo,

I have provided all the code involved hoping that would be enough for Telerik to provide a solution. 

See the code above which I provided and let me know if you see anything that needs correcting.

Thanks!
0
Dimo
Telerik team
answered on 28 Jul 2008, 10:29 AM
Hello George,

If I understand your code correctly, you want to avoid the situation when the sort order is "None" and switch it to "Ascending". However, the IF statement is not correct, because it is never "true". As a result, you sometimes add a sort expression with no SortOrder and that is why the column is highlighted. Please use this code instead:


            if (Convert.ToString(e.NewSortOrder) == "None")
            {
                sortExpr.SortOrder = GridSortOrder.Ascending;
            }
            else
            {
                sortExpr.SortOrder = e.NewSortOrder;
            }

By the way, if you want to switch between Ascending and Descending only, you can set the AllowNaturalSort property to False, as described here:

RadGrid - Controlling sorting modes



Best wishes,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 28 Jul 2008, 02:06 PM
I tried that and there are three sorts......... Ascending, Descending, and Null. or None which is really messes things up.  Does this third click on the column mean return to unsort?  If so how do I get the column not to be highlighted to show that it is not sorted anymore?
0
Dimo
Telerik team
answered on 29 Jul 2008, 06:47 AM
Hello George,

Yes, SortOrder = "None" means that the column is not sorted and the data is displayed the way that it is retrieved from the data source (unless there is sorting applied on another column).

In order to remove the SortedBackColor from a column, which is currently not sorted, please change your code as I have shown you in my previous post.

Greetings,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 29 Jul 2008, 03:07 PM
I have made the change and my sort now appears in the following order:
Ascending
None
Descending

Shouldn't it be?
Ascending
Descending
None
0
Accepted
Dimo
Telerik team
answered on 30 Jul 2008, 04:10 PM
Hello George,

The order of sorting is by default

Ascending
Descending
None

It will remain such if you remove the following code:


if (!e.Item.OwnerTableView.SortExpressions.ContainsExpression(e.SortExpression)) 

            // The intial page load will not have a NewSortOrder, so Ascending is set to default 
            GridSortExpression sortExpr = new GridSortExpression(); 
            sortExpr.FieldName = e.SortExpression; 
            sortExpr.SortOrder = GridSortOrder.Ascending; 
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr); 
}


Let us know if you need further advice. In this case, please provide some details about what exactly you want to achieve.


All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Mike
Top achievements
Rank 1
Share this question
or