I am using a Radgrid which allows the columns to be sorted and a sort icon is displayed when a column is sorted. If the same column is clicked to sort continuously for 3 times, the sort icon is not being shown the third time. Also the fourth time I click the same column, there is no change in the sorting order. Is there a third state other than asc and desc? The demos in telerik site also displays the same behaviour.
Given below is the code snippet for SortCommand handler:
Select
Case e.OldSortOrder
Case GridSortOrder.None, GridSortOrder.Descending
BindResults(pindex,
e.CommandArgument & " asc")
Exit Select
Case GridSortOrder.Ascending
BindResults(pindex,
e.CommandArgument & " desc")
Exit Select
Any help in this regard is greatly appreciated.
Thanks
PMR.
25 Answers, 1 is accepted
When sorting is enabled, arrow buttons appear on the column headers that allow users to select a sorting mode for each column.
There are three sorting modes:
- Ascending
- Descending
- No Sort
To limit the sorting modes to two-way sorting (ascending and descending), set the MasterTableView.AllowNaturalSort property or the GridTableView.AllowNaturalSort property to False.
For more information, please refer to the following article:
Controlling sorting modes
Kind regards,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Most probably you are binding the grid calling DataBind() method. Note that simple data-binding can be used in simple cases when you do not require the grid to perform complex operations such as sorting, paging, grouping etc. For advanced features such as those, RadGrid must be bound through the NeedDataSource event. When using the NeedDataSource event, RadGrid can automatically accommodate the appropriate database operations without the need for you explicitly handle any sorting, paging, grouping, and so on.
Kind regards,
Pavlina
the Telerik team
You are probably right, as I was doing a DataBind. Ironically, GridView made this much easier with a SqlDataSource via the DataSourceID property which handled all the sorting and paging automatically. Rather than spend days figuring out how to convert my GridView to a RadGrid (having already wasted a day), I opted to spend hours figuring out how to Export to Excel with my GridView.
As a general concern, and at times incredible frustration, with using many Telerik controls I find it, how should I put this, irritating that they are implemented so differently from the .NET controls in very key ways. For example, why call rows in a RadGrid items instead of rows? I see no point in this. Why have a special event for sorting and paging when this is such an easily overlooked detail? I don't always agree with Microsoft's naming conventions and practices either, but for the sake of development productivity, it's beneficial at times to simply follow their lead to make things more intuitive, especially when something is based on their .NET framework.
Anyway, I'll be the last to throw stones when it comes to usability, but I just wanted to bring this up so the Telerik team can consider how to make their controls more intuitive and easy to implement, particularly when converting .NET controls to Telerik, or at least have more succinct documentation highlighting key differences between them such as this one.
Best, :)
Matthew
The declarative syntax of Telerik RadGrid is quite similar to that of the Microsoft GridView control, which makes the migration a pretty straightforward task. Compare the source codes in the ASPX tab.
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/migration/defaultcs.aspx
However, complete white paper which can additionally reduce the learning curve when migrating from MS GridView to RadGrid is available here: White paper (page 14)
Regards,
Pavlina
the Telerik team
I think my GridView was far too complex to make the migration easy, involving a lot of custom column binding in the codebehind, so the example page you provided is just too trivial to be helpful in my case. Nevertheless, the sorting and paging worked our of the box, but for some reason it broke when I tried to do the same thing with RadGrid. No matter, a venture for another day I suppose. Thanks for the support. ;)
If you are using simple data-binding to bind the grid, you need to assign the data source and rebind the grid after any data operation such as paging, sorting, editing, and so on. This model copies exactly the behavior of MS DataGrid. More information is available in th article below:
http://www.telerik.com/help/aspnet-ajax/grid-simple-data-binding.html
Regards,
the Telerik team
My RadGrid sorting does not work properly. I figure out that why its not working properly. I need its solution. Let me explain.
public partial class TestPage: ParentClass // System.Web.UI.Page
{
}
I inherit My ParentClass instead of System.Web.UI.Page. So RadGrid not working properly. I have some session mgt in ParentClass.
and My ParentClass is inherit from System.Web.UI.Page. But when i click on RadGrid sorting its does not properly. It sort only one time and some time i click on one column it sort other column.
Can you have any solution that why its happening?
If i did not inherit it from ParentClass and inherit it from System.Web.UI.Page . its work great.
Thanks,
Muhammad Waseem
Telerik Team
The topic below describes some of the considerations you should keep in mind when binding a grid to custom collection:
http://www.telerik.com/help/aspnet-ajax/grid-tips-when-binding-to-custom-collections.html
Read it carefully and let me know if you need additional assistance.
All the best,
Pavlina
the Telerik team
I figure out the previous issue. i am overriding many classes before loading the page. there is some logical mistake there. now i remove that part from parent classes. Now its work great. Thanks for assistance.
Thanks,
Muhammad Waseem
the Telerik team
Can anyone pls help me to sort it out.
Thanks & Regards,
K.Murali Krishna.
Sorting works fine when the RadGrid is bound using Advanced Data-binding method. Please provide your code if it doesn't help.
Thanks,
Princy.
For me sorting for main grid is working fine. But when comes to sorting in inner grid.......it is not working. i handled sort command for main grid as follows:
GridSortExpression sortExpr = new GridSortExpression();
switch (e.OldSortOrder)
{
case GridSortOrder.None:
// sortExpr.FieldName = e.SortExpression;
// sortExpr.SortOrder = GridSortOrder.Descending;
ViewState["SortCol"] = e.SortExpression;
ViewState["SortOrder"] = "asc";
// e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
break;
case GridSortOrder.Ascending:
//sortExpr.FieldName = e.SortExpression;
//sortExpr.SortOrder = IssueGrid.MasterTableView.AllowNaturalSort ? GridSortOrder.None : GridSortOrder.Descending;
ViewState["SortCol"] = e.SortExpression;
ViewState["SortOrder"] = "desc";
// e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
break;
case GridSortOrder.Descending:
//sortExpr.FieldName = e.SortExpression;
//sortExpr.SortOrder = GridSortOrder.Ascending;
ViewState["SortCol"] = e.SortExpression;
ViewState["SortOrder"] = "asc";
// e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
break;
}
MyGrid.MasterTableView.CurrentPageIndex = 0;
// e.Canceled = true;
MyGrid.MasterTableView.Rebind();
For inner grid.......how to handle the sort event? While i click on col. header in inner grid it is throwing error as :
<col. header> is neither a DataColumn nor a DataRelation for table Table.
Suggestions please............
like:
<telerik:GridTemplateColumn DataField="_PONumber" HeaderStyle-HorizontalAlign="Center" HeaderText="PO #" Visible="true">
<ItemTemplate>
<asp:Label ID="lblPONumber" Text='<%# Eval("_PONumber") %>' runat="server">
</asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</telerik:GridTemplateColumn>
Regards,
Muhammad Waseem
the telerik team
Hello
I am using RadGrid for sorting, filtering and paging. I have a problem with sorting, it doesn;t sort ascending, it simply ignores it. I don't want to use AllowNaturalSort property to False, i want all 3 sorting modes to work. I think i am missing a tag or something in RadGrid, but i can;t figure it out which one. Can u help me?
//sortcomand method
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);
}
}
//grid
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" UpdateInitiatorPanelsOnly="true">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true"
AllowSorting="True" GridLines="None" AutoGenerateColumns="False" OnSortCommand="RadGrid1_SortCommand" OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView AllowMultiColumnSorting="true">
<Columns>
<telerik:GridBoundColumn SortExpression="IovationDeviceID" HeaderText="Iovation Device ID" HeaderButtonType="TextButton"
DataField="IovationDeviceID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="IovationDeviceStatus" HeaderText="Iovation Result" HeaderButtonType="TextButton"
DataField="IovationDeviceStatus">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="EventType" HeaderText="Integration Point" HeaderButtonType="TextButton"
DataField="EventType">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="Ins" HeaderText="Timestamp" HeaderButtonType="TextButton"
DataField="Ins">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<PagerStyle AlwaysVisible="true" />
</telerik:RadGrid>
Please find attached a working example in which I used the code you provided and let me know if this is what you are trying to achieve.
Regards,
Pavlina
Telerik
Hi Pavlina,
I have some issue with Rad sorting on Paging.
I have around 4000 rows in it.
But i am unable to sort it. I am directly binding the data to grid from datatable.
Any help will be greatly appreciated.
<telerik:RadGridrunat="server"ID="RadGrid1"AllowPaging="True"AllowSorting="True"
OnSortCommand="RadGrid1_SortCommand"OnNeedDataSource="RadGrid1_NeedDataSource"
GroupPanelPosition="Top"ResolvedRenderMode="Classic"Height="230"OnPageIndexChanged="RadGrid1_PageIndexChanged">
<ClientSettingsAllowColumnHide="True"AllowRowHide="True"AllowColumnsReorder="True"
ReorderColumnsOnClient="True">
<ClientEventsOnRowClick="RowSelected"/>
<SelectingAllowRowSelect="True"/>
<ScrollingAllowScroll="True"UseStaticHeaders="True"SaveScrollPosition="true"FrozenColumnsCount="2">
</Scrolling>
<ResizingEnableRealTimeResize="True"ResizeGridOnColumnResize="True"AllowColumnResize="true"
ClipCellContentOnResize="false"></Resizing>
</ClientSettings>
<MasterTableView>
<PagerStyleAlwaysVisible="true"/>
<Columns>
</Columns>
</MasterTableView>
</telerik:RadGrid>​
When the data is less like 4 rows , it works as expected.
Please help.
I tested the provided code and as you can see from the attached project sorting is working without problems.
Regards,
Pavlina
Telerik
Hi,
In your project you have tested the sorting with very few rows.
When the data is less, the sorting and paging works perfectly at my end also. The problem starts when the data is more that 1000 rows.
May I ask you modify the project I sent you so that the issue can be observed and send it to us via support ticket. We will examine it locally and will advice you further.
Regards,
Pavlina
Telerik
Hi Palvina, I am sorry if I am doing a wrong post but I am stuck with a sorting issue and spent a lot of time on it without any results. Please allow me to explain and let me know if you can help.
My question is simple, I need to implement Multi Column sorting in my RadGrid Columns and I am not able to do so. I have added the Sort Expression as below (see the code snippet). The AllowMultiSort property is also set as True.
Apart from the above, please let me know if I need to add any code to my code behind CS file to achieve this. And if yes then which is the correct event to do so.
Thanks in advance for your help.
<SortExpressions>
<telerik:GridSortExpression FieldName="ProviderKey" SortOrder="Ascending" />
<telerik:GridSortExpression FieldName="ProviderName" SortOrder="Ascending" />
<telerik:GridSortExpression FieldName="MemberName" SortOrder="Ascending" />
<telerik:GridSortExpression FieldName="MemberKey" SortOrder="Ascending" />
<telerik:GridSortExpression FieldName="Product" SortOrder="Ascending" />
<telerik:GridSortExpression FieldName="DateOfBirth" SortOrder="Ascending" />
<telerik:GridSortExpression FieldName="pyRiskScore" SortOrder="Ascending" />
<telerik:GridSortExpression FieldName="RiskScore" SortOrder="Ascending" />
</SortExpressions>
hello
columns can be sorting in my PC (developed environment) without any event but it doesn`t work in another PC
so would you tell me what happened?
Hi Aseman,
You can try these following suggestions to troubleshoot the issue:
1. Ensure that the grid is not using the DataBind() method:
https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-bind-radgrid-properly-on-server-side
2. If you are using AJAX, you can temporarily remove it and check for hidden script errors:
https://www.telerik.com/support/kb/aspnet-ajax/ajaxmanager/details/get-more-descriptive-errors-by-disabling-ajax
Regards,
Eyup
Progress Telerik