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

RadGrid Sorting

11 Answers 259 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BALA MUKUND
Top achievements
Rank 1
BALA MUKUND asked on 23 Jun 2008, 05:54 PM
Hello,

I currently have a RadGrid that sorts DESC (on certain columns) using the SortExpression property of a bound column. These are the sequence of events that happen currently

1 - Grid populates with no sorting
2- User clicks on a column (for which the sortexpression has been set) and the column sorts DESC
3- User clicks on the same column - the column goes back to No Sort.

How can I enable the column to sort ASC instead of No Sort on the second click?

Thanks
Bala

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jun 2008, 04:51 AM
Hi Bala,

Go through the following help article.
Controlling sorting modes

Shinu.
0
BALA MUKUND
Top achievements
Rank 1
answered on 24 Jun 2008, 01:25 PM
The way I currently control is using the following code snippet


boundColumn->SortExpression = 'COLUMN DESC'

I tried adding another expression

COLUMN DESC, COLUMN ASC - this gave me a very different result. The column kept sorting DESC but the arrow showed ASC

Any suggestions to this method?

Thanks

0
Princy
Top achievements
Rank 2
answered on 25 Jun 2008, 07:14 AM
Hi Bala,

Go through the following help document links.

Sorting expressions
Applying custom sort criteria

Princy.
0
Mike
Top achievements
Rank 1
answered on 26 Jun 2008, 04:32 PM
Why are we just referencing articles that we have read and did not provide the solution.  I am having the same problem, the following code you supplied sets  [e.NewSortOrder to None when we want Descending....

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

I even went the extreme of  doing the following and it did not sort descending.

    protected void RadGrid1_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)  
    {  
        if (!e.Item.OwnerTableView.SortExpressions.ContainsExpression(e.SortExpression))  
        {  
            GridSortExpression sortExpr = new GridSortExpression();  
            sortExpr.FieldName = e.SortExpression;  
            sortExpr.SortOrder = GridSortOrder.Ascending;  
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);  
        }  
        else  
        {  
            GridSortExpression sortExpr = new GridSortExpression();  
            sortExpr.FieldName = e.SortExpression;  
            sortExpr.SortOrder = GridSortOrder.Descending;  
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);  
        }  
      } 

We need a solution not more links!!! Thank you and we await your reponse.
0
Yavor
Telerik team
answered on 27 Jun 2008, 05:23 AM
Hi Mike,

Attached to this message is an application which:

1. Grid populates with no sorting
2- User clicks on a column (for which the sortexpression has been set) and the column sorts DESC
3- The column will be sorted to ASC on next sort.

I hope this helps.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 27 Jun 2008, 01:08 PM

Yavor,

Thanks for the snippet it worked the first time but any sort afterwards persisted at Ascending sort.  This made me see what elements I had access to and the NewSortOrder was a trigger that could be used.  Take a look at my update and tell me if you see any possible downside.  It seems to work great now if I can just clear the sort once clicked on the column I will be in business

  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();  
        }          
    } 
0
Yavor
Telerik team
answered on 30 Jun 2008, 01:08 PM
Hello Mike,

I reviewed your code, and it in an optimal solution to the custom functionality that you are seeking. Further, can you please elaborate on the additional functionality that you mentioned - are you looking to remove the sorting expression for the grid, when you click on the column, or the column header?

All the best,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 1
answered on 30 Jun 2008, 01:12 PM

Yes, when I click on the column it sorts decending, another click ascending and vice versa.  However, I have multiple column select enabled and I cannot get the columns remove the sort, they stay highlighted.

0
Yavor
Telerik team
answered on 02 Jul 2008, 09:59 AM
Hello Mike,

You can remove the sorting expression dynamically, from the control, just as you added them. Let me know if this is a suitable option for you.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Vaibhav
Top achievements
Rank 1
answered on 02 Jul 2008, 10:13 AM
Hi,

I could not sort properly using sortorder and sortexpression in sortcommand only.

I set viewstates for sortorder and sortexpression then called bindgrid() sub.
Using the viewstates in bindgrid(), I sorted dataview object. This dataview object is given as source to grid.

This worked for me but I know this is a workaround.

Regards,
Vaibhav
0
Yavor
Telerik team
answered on 04 Jul 2008, 11:31 AM
Hi Vaibhav,

Indeed, this is a work-around, achieving the same effect. If the issue is persisting at your end, you can open a formal support ticket, and send us a small project sample, which I can review locally, and possibly provide more details.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
BALA MUKUND
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
BALA MUKUND
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Yavor
Telerik team
Vaibhav
Top achievements
Rank 1
Share this question
or