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

Sorting on RadGrid not working properly

25 Answers 1923 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PMR IN
Top achievements
Rank 1
PMR IN asked on 21 Oct 2009, 07:59 AM
Hi,
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

Sort by
0
Accepted
Pavlina
Telerik team
answered on 21 Oct 2009, 08:51 AM
Hello,

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,

Pavlina
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.
0
PMR IN
Top achievements
Rank 1
answered on 21 Oct 2009, 09:00 AM
Thanks Pavlina. I just saw that property for client mode sorting. That worked.
0
Matthew
Top achievements
Rank 1
answered on 30 Aug 2012, 12:44 AM
This is not the case with my grid. I have a grid with <MasterTableView AllowPaging="true" AllowSorting="true" AllowNaturalSort="false"> and neither paging nor sorting is working. Truth be told, I'm having numerous issues with RadGrid after converting my previous GridView control to a RadGrid. I'm using the latest version (2012.2.724.35) as well. :(
0
Pavlina
Telerik team
answered on 03 Sep 2012, 02:13 PM
Hi Matthew,

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
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Matthew
Top achievements
Rank 1
answered on 03 Sep 2012, 03:14 PM
Thank you Pavlina,

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
0
Pavlina
Telerik team
answered on 06 Sep 2012, 01:18 PM
Hello,

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
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Matthew
Top achievements
Rank 1
answered on 06 Sep 2012, 04:36 PM
Thanks Pavlina,

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. ;)
0
Pavlina
Telerik team
answered on 11 Sep 2012, 12:49 PM
Hello,

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
However, the easiest way to bind the grid is to use the advanced data binding of a RadGrid control by handling the NeedDataSource event. RadGrid fires the NeedDataSource event each time it needs to be bound to a data source. The NeedDataSource event is especially designed to facilitate the work of the developers as you do not need to handle any sorting/paging/grouping/filtering/etc. commands manually. Under such circumstances Telerik RadGrid will be "smart enough" to perform the corresponding operation automatically.

Regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Waseem
Top achievements
Rank 1
answered on 17 Jan 2013, 05:26 PM
Hi

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
0
Pavlina
Telerik team
answered on 22 Jan 2013, 06:08 PM
Hello,

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
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Waseem
Top achievements
Rank 1
answered on 22 Jan 2013, 06:13 PM
Hi Pavlina
 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
0
Murali
Top achievements
Rank 1
answered on 21 May 2013, 01:10 PM
HI I am trying to implement the sorting functionality in my radgrid control. But which column header i am selecting first after page load that col only is satisfying the sort functionality and remaining cols not. Why like this? 
Can anyone pls help me to sort it out.



Thanks & Regards,
K.Murali Krishna.
0
Princy
Top achievements
Rank 2
answered on 22 May 2013, 06:55 AM
Hi,

Sorting works fine when the RadGrid is bound using Advanced Data-binding method. Please provide your code if it doesn't help.

Thanks,
Princy.
0
Waseem
Top achievements
Rank 1
answered on 23 May 2013, 11:25 PM
Hi Murali
Just  allowmulticolumnsorting to false.

<telerik:RadGrid ID="RadGrid1" runat="server" PageSize="20" Width="100%" AllowSorting="True">
                        <mastertableview datakeynames="GoalID" allowmulticolumnsorting="false">
and so on.

Regards,
Muhammad Waseem
the telerik team

0
Murali
Top achievements
Rank 1
answered on 27 May 2013, 01:30 PM
Hi,

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............
0
Waseem
Top achievements
Rank 1
answered on 28 May 2013, 08:39 AM
you need to set DataField="columnName"
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
0
Alexandra
Top achievements
Rank 1
answered on 16 Jul 2015, 09:49 AM

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>

 

0
Pavlina
Telerik team
answered on 21 Jul 2015, 08:50 AM
Hello,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Nitin
Top achievements
Rank 1
answered on 16 Oct 2015, 09:09 AM

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.     

0
Pavlina
Telerik team
answered on 16 Oct 2015, 03:38 PM
Hi,

I tested the provided code and as you can see from the attached project sorting is working without problems.

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Nitin
Top achievements
Rank 1
answered on 16 Oct 2015, 05:12 PM

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.     

0
Pavlina
Telerik team
answered on 20 Oct 2015, 03:48 PM
Hello,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Gaurav
Top achievements
Rank 1
answered on 03 Nov 2015, 12:48 PM

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>

0
Aseman
Top achievements
Rank 1
Veteran
answered on 13 Oct 2019, 08:55 AM

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?

0
Eyup
Telerik team
answered on 16 Oct 2019, 07:57 AM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
PMR IN
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
PMR IN
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Waseem
Top achievements
Rank 1
Murali
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Alexandra
Top achievements
Rank 1
Nitin
Top achievements
Rank 1
Gaurav
Top achievements
Rank 1
Aseman
Top achievements
Rank 1
Veteran
Eyup
Telerik team
Share this question
or