Sorting on RadGrid not working properly

24 posts, 1 answers
  1. PMR IN
    PMR IN avatar
    6 posts
    Member since:
    Aug 2009

    Posted 21 Oct 2009 Link to this post

    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.
  2. Answer
    Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 21 Oct 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. PMR IN
    PMR IN avatar
    6 posts
    Member since:
    Aug 2009

    Posted 21 Oct 2009 Link to this post

    Thanks Pavlina. I just saw that property for client mode sorting. That worked.
  5. Matthew
    Matthew avatar
    15 posts
    Member since:
    Dec 2004

    Posted 29 Aug 2012 Link to this post

    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. :(
  6. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 03 Sep 2012 Link to this post

    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.
  7. Matthew
    Matthew avatar
    15 posts
    Member since:
    Dec 2004

    Posted 03 Sep 2012 Link to this post

    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
  8. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 06 Sep 2012 Link to this post

    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.
  9. Matthew
    Matthew avatar
    15 posts
    Member since:
    Dec 2004

    Posted 06 Sep 2012 Link to this post

    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. ;)
  10. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 11 Sep 2012 Link to this post

    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.
  11. <span>w</span>
    <span>w</span> avatar
    84 posts
    Member since:
    Jun 2012

    Posted 17 Jan 2013 Link to this post

    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
  12. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 22 Jan 2013 Link to this post

    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.
  13. <span>w</span>
    <span>w</span> avatar
    84 posts
    Member since:
    Jun 2012

    Posted 22 Jan 2013 Link to this post

    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
  14. Murali
    Murali avatar
    2 posts
    Member since:
    Apr 2013

    Posted 21 May 2013 Link to this post

    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.
  15. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 May 2013 Link to this post

    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.
  16. <span>w</span>
    <span>w</span> avatar
    84 posts
    Member since:
    Jun 2012

    Posted 23 May 2013 Link to this post

    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

  17. Murali
    Murali avatar
    2 posts
    Member since:
    Apr 2013

    Posted 27 May 2013 Link to this post

    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............
  18. <span>w</span>
    <span>w</span> avatar
    84 posts
    Member since:
    Jun 2012

    Posted 28 May 2013 Link to this post

    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
  19. Alexandra
    Alexandra avatar
    1 posts
    Member since:
    Jul 2015

    Posted 16 Jul 2015 Link to this post

    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>

     

  20. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 21 Jul 2015 Link to this post

    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
  21. Nitin
    Nitin avatar
    3 posts
    Member since:
    May 2015

    Posted 16 Oct 2015 in reply to Pavlina Link to this post

    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.     

  22. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 16 Oct 2015 Link to this post

    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
  23. Nitin
    Nitin avatar
    3 posts
    Member since:
    May 2015

    Posted 16 Oct 2015 in reply to Pavlina Link to this post

    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.     

  24. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 20 Oct 2015 Link to this post

    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
  25. Gaurav
    Gaurav avatar
    5 posts
    Member since:
    Feb 2015

    Posted 03 Nov 2015 in reply to Pavlina Link to this post

    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>

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017