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
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
Go through the following help document links.
Sorting expressions
Applying custom sort criteria
Princy.
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.
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
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(); |
} |
} |
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
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.
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
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
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