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

Hierarchical RadGrid sorting problems

9 Answers 255 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lajos
Top achievements
Rank 1
Lajos asked on 26 Aug 2011, 01:39 PM

Hello, Telerik, I have a question to you regarding the hierarchical RadGrids.

I'm using a hierarchical RadGrid (Telerik control) but there are some bugs regarding the sort of the second level. I have two levels and the second level is loaded based on the first level.

Columns of the first level: Foo1, Foo2, Foo3

Columns of the second level: Bar1, Foo2, Bar2, Bar3

Binding is issued through a function.

Problems:

  1. If a single row of the first level is expanded (we can see a single sub-grid from the second level) and I want to sort by Bar1, the sort happens, but an error occures:

    Uncaught TypeError: Cannot call method 'sort' of null

  2. If a single row of the first level is expanded (we can see a single sub-grid from the second level) and I want to sort the second level by Foo2, the sort happens for the parent grid's (!) Foo2 column

  3. If two rows of the first level are expanded (we can see two sub-grids from the second level) and I want to sort both the subgrids by the same column a strange rectangle appears instead of the ascending/descending sign, I get the same error as described in the first problem but the sorting is not issued.

I would like to get rid of these problems, my question is the following:

If we have a hierarchical RadGrid and both the first and the second level is sortable how can I implement a sort of the second level to be free of bugs?

Thank you in advance for your responses.

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Aug 2011, 01:52 PM
Hello Lajos,

Take a look at the following demo.
Grid / Client-side Hierarchy Loading.

Thanks,
Princy
0
Lajos
Top achievements
Rank 1
answered on 30 Aug 2011, 03:20 PM
Thank you,

after studying your demo and trying out various things I've managed to solve the main issue. However, I'm keeping track of the history of sorting and I need to know whenever a sort command was processed the level of the column where the sort command was issued. This would be easy based on the columns, but there is a problem:

My grid has two levels and each of these levels is associated with a datasource. However, I have a column on both level one and level two called 'Foo', so based on the column names I won't be able to determine whether the sort command should be processed on level 1 or level 2.

As a result, my question is the following:
If I click on the header of a column how can my Javascript code determine the level where the command was processed. If I could get a number, like 1, which would stand for the root of the grid tree, or a number 2 which would stand for nodes from the second level, that would be nice. Is this possible?

Also, I have a root and it can have as many children nodes as the number of rows. If I get a 2 for level number, how can I determine the node where the command is issued?

Any help is appreciated,
best regards,
Lajos Arpad.
0
Lajos
Top achievements
Rank 1
answered on 31 Aug 2011, 06:29 PM
Hello, Princy,

it seems to me that Telerik has a bug regarding the sort of automatically generated columns in lower levels of a hierarchical RadGrid.

I've made a page based on the demo given by you where the columns are automatically generated. The problem (I'm almost sure this is a Telerik bug) is when you open two separate child grids in the same time and you want to sort both of them by the same column. It seems to me that the classes of rgSortAsc and rgSortDesc are not given consistently to the inputs in this case. If ChildGrid1 is sorted by Foo and I sort ChildGrid2 by Foo, the input in the header of Foo in ChildGrid1 will contain a rectangle instead of the image associated to the column. This is because after I click the header of Foo in ChildGrid2, the input in the header of Foo in ChildGrid1 will no longer contain the class of either rgSortAsc or rgSortDesc. I'm sure you can reproduce the bug using my sample test code, I'll give you both the markup and the code behind in Visual Basic:

Markup:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" MasterPageFile="~/Site.Master" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="ContentHead" runat="server" ContentPlaceHolderID="HeadContent" Visible="true">
</asp:Content>

<asp:Content ID="ContentBody" runat="server" ContentPlaceHolderID="PageBody" Visible="true">

        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>


        <telerik:RadGrid ID="RadGrid1" runat="server"
            PageSize="3" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True"
            GridLines="None">
            <MasterTableView ClientDataKeyNames="CustomerID" DataKeyNames="CustomerID"
                AllowMultiColumnSorting="True" HierarchyLoadMode="Client" Width="100%">
                <Columns>
                </Columns>
                <DetailTables>
                    <telerik:GridTableView ClientDataKeyNames="OrderID" DataKeyNames="OrderID" HierarchyLoadMode="Client"
                        Width="100%">
                        <Columns>
                        </Columns>
                        <SortExpressions>
                            <telerik:GridSortExpression FieldName="Quantity" SortOrder="Descending"></telerik:GridSortExpression>
                        </SortExpressions>
                    </telerik:GridTableView>
                </DetailTables>
                <SortExpressions>
                    <telerik:GridSortExpression FieldName="CompanyName"></telerik:GridSortExpression>
                </SortExpressions>
            </MasterTableView>
        </telerik:RadGrid>

</asp:Content>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code Behind:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Imports System
Imports Telerik.Web.UI

Partial Class Default2
    Inherits System.Web.UI.Page

    Private Class FirstLevel
        Public Property CustomerID As Integer
        Public Property ContactName As String
        Public Property CompanyName As String
    End Class

    Private Class SecondLevel
        Public Property OrderID As Integer
        Public Property UnitPrice As Integer
        Public Property Quantity As Integer
        Public Property Discount As Integer
        Public Property CompanyName As String
    End Class

    Protected Property cols As Telerik.Web.UI.GridColumnCollection = Nothing
    Protected Property cols2 As Telerik.Web.UI.GridColumnCollection = Nothing

    Protected Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        Dim list As New List(Of FirstLevel)
        list.Add(New FirstLevel With {.CustomerID = 1, .ContactName = "1", .CompanyName = "1"})
        list.Add(New FirstLevel With {.CustomerID = 2, .ContactName = "2", .CompanyName = "2"})
        RadGrid1.DataSource = list
    End Sub

    Protected Sub RadGrid1_DetailTableDataBind(ByVal source As Object, ByVal e As GridDetailTableDataBindEventArgs) Handles RadGrid1.DetailTableDataBind
        Dim list As New List(Of SecondLevel)
        list.Add(New SecondLevel With {.OrderID = 1, .UnitPrice = 1, .Quantity = 1, .Discount = 1, .CompanyName = "1"})
        list.Add(New SecondLevel With {.OrderID = 3, .UnitPrice = 3, .Quantity = 3, .Discount = 3, .CompanyName = "3"})
        list.Add(New SecondLevel With {.OrderID = 2, .UnitPrice = 2, .Quantity = 2, .Discount = 2, .CompanyName = "2"})
        e.DetailTableView.DataSource = list
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

End Class
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thank you in advance for any help given,
yours truly,
Lajos Arpad.
0
Marin
Telerik team
answered on 01 Sep 2011, 12:42 PM
Hello Lajos,

 I checked the attached sample code and we confirm that the issue with the styles of the sort indicators (the little triangles) is a bug in RadGrid. We have logged it in our system and it will be resolved in future releases of the controls.
On your second questions: each tableView object (MasterTableView, DetailTableView) has a corresponding Name property which you can set and use to distinguish when the command is fired from the master or detail table. You can get a reference to the specific table view either through an item or a column in the grid which have corresponding properties OwnerTableView or Owner on the server.

Greetings,
Marin
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Lajos
Top achievements
Rank 1
answered on 01 Sep 2011, 01:06 PM
Hello, Martin Georgiev,

Thank you for your answers and I wish you all the best.

Best regards,
Lajos Arpad.
0
Steve
Top achievements
Rank 1
answered on 19 Nov 2011, 04:57 AM
It seems from the threads that there's an issue with the sort images (up/down arrow) which will be addressed in a later release, but I can't reliably even get the sample page at http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultvb.aspx to sort consistently even if I ignore the sort images and only click on the column header texts.  I'm not reproducing the sample myself and just using it at your site.

I've tried on several browsers and experimented with fresh page loads versus trying to see if it stops sorting after x attempts.but cannot find the pattern.

Am I missing something or...

1. Load the above page at your site.

2. Just to try and keep it simple, collapse the pre-expanded levels.

3. Click on the column header "Contact Name" - no change in the sort.

4. Click on the column header "Company" - yay!  you get a sort.

5. Click on the column header "Company" a second time to reverse the sort (at least that's what I think it would do intuitively) and the sorts change, but it appears to have sorted on "Contact Name"...

6. Repeat in various combinations and it doesn't seem to work reliable if at all.


I like this example you've written at that page above but cannot use it if the basic top level sorting is not reliable.

Awaiting your thoughts, thanks.  :)
0
Steve
Top achievements
Rank 1
answered on 19 Nov 2011, 05:34 AM
By the way, to give credit where credit is due, I love the products and use them extensively.  I just need help on what, if anything, I'm doing wrong with this issue. :)
0
Lajos
Top achievements
Rank 1
answered on 21 Nov 2011, 10:03 AM
Hello, Steve,

I experienced the same problems with the hierarchical sort when the columns are automatically generated and I've set AllowSorting="false" in the inner grid to not allow this bug to occur, but when sorting on lower levels will be possible I'll set the above mentioned flag to true.

I wish you all the best,

Lajos Arpad.
0
Marin
Telerik team
answered on 22 Nov 2011, 06:05 PM
Hi Steve,

I tried to replicate the problem following your steps on the demo but to no avail. The sorting there was consistent every time in all browsers. Do you still reproduce the same problem on the exact same demo? You can also check some of the other demos about sorting here:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/sorting/defaultvb.aspx

As for the other issue that Lajos reported with the missing sort images in the auto-generated columns, we are currently working on it and hopefully it will be up for the next service pack.

Kind regards,
Marin
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
Tags
Grid
Asked by
Lajos
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Lajos
Top achievements
Rank 1
Marin
Telerik team
Steve
Top achievements
Rank 1
Share this question
or