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

Is that bug in radgrid Self-referencing hierarchy?

5 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen Lam
Top achievements
Rank 1
Stephen Lam asked on 09 Mar 2010, 02:57 AM
Hi,
I found that I could not edit the Self-referencing hierarchy and there is filtering bug in Self-referencing hierarchy too!Here is the video demo and my code:

http://www.youtube.com/watch?v=X_HrlJJSgko

<form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
    <div> 
        <asp:AccessDataSource ID="adsCategories" runat="server"   
            DataFile="~/App_Data/dbmx.mdb"   
            SelectCommand="SELECT * FROM [Categories] where isDelete = False"></asp:AccessDataSource> 
        <asp:AccessDataSource ID="adsProducts" runat="server"   
            DataFile="~/App_Data/dbmx.mdb"   
            SelectCommand="SELECT * FROM [Products] where isDelete = False"></asp:AccessDataSource> 
        <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" DataSourceID="adsCategories"   
            GridLines="None" AllowFilteringByColumn="True" AllowPaging="True"   
            AutoGenerateEditColumn="True" Skin="Office2007">  
            <MasterTableView DataKeyNames="categoryID,categoryParentID" HierarchyLoadMode="Client" DataSourceID="adsCategories" HierarchyDefaultExpanded="False">  
                <SelfHierarchySettings KeyName="categoryID" ParentKeyName="categoryParentID" /> 
            <RowIndicatorColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
 
            <ExpandCollapseColumn> 
            <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            </MasterTableView> 
            <ClientSettings> 
                <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
            </ClientSettings> 
        </telerik:RadGrid> 
    </div> 
    </form> 
Protected Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated  
        If TypeOf e.Column Is GridExpandColumn Then 
            e.Column.Visible = False 
        ElseIf TypeOf e.Column Is GridBoundColumn Then 
            e.Column.HeaderStyle.Width = Unit.Pixel(100)  
        End If 
    End Sub 
 
    Public Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Load  
        If Assembly.GetAssembly(GetType(ScriptManager)).FullName.IndexOf("3.5") <> -1 Then 
            RadGrid1.MasterTableView.FilterExpression = "it[""categoryParentID""] = Convert.DBNull" 
        Else 
            RadGrid1.MasterTableView.FilterExpression = "categoryParentID IS NULL" 
        End If 
    End Sub 
 
    Public Sub Page_PreRenderComplete(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.PreRenderComplete  
        HideExpandColumnRecursive(RadGrid1.MasterTableView)  
    End Sub 
 
    Public Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)  
        Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView)  
        For Each nestedViewItem As GridNestedViewItem In nestedViewItems  
            For Each nestedView As GridTableView In nestedViewItem.NestedTableViews  
                nestedView.Style("border") = "1" 
 
                Dim MyExpandCollapseButton As Button = DirectCast(nestedView.ParentItem.FindControl("MyExpandCollapseButton"), Button)  
                If nestedView.Items.Count = 0 Then 
                    If Not MyExpandCollapseButton Is Nothing Then 
                        MyExpandCollapseButton.Style("visibility") = "hidden" 
                    End If 
                    nestedViewItem.Visible = False 
                Else 
                    If Not MyExpandCollapseButton Is Nothing Then 
                        MyExpandCollapseButton.Style.Remove("visibility")  
                    End If 
                End If 
 
                If nestedView.HasDetailTables Then 
                    HideExpandColumnRecursive(nestedView)  
                End If 
            Next 
        Next 
    End Sub 
 
    Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated  
        CreateExpandCollapseButton(e.Item, "categoryID")  
 
        If TypeOf e.Item Is GridHeaderItem AndAlso Not e.Item.OwnerTableView Is RadGrid1.MasterTableView Then 
            e.Item.Style("display") = "none" 
        End If 
 
        If TypeOf e.Item Is GridNestedViewItem Then 
            e.Item.Cells(0).Visible = False 
        End If 
    End Sub 
 
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound  
        CreateExpandCollapseButton(e.Item, "categoryID")  
    End Sub 
 
    Public Sub CreateExpandCollapseButton(ByVal item As GridItem, ByVal columnUniqueName As String)  
        If TypeOf item Is GridDataItem Then 
            If item.FindControl("MyExpandCollapseButton"Is Nothing Then 
                Dim button As New Button()  
                AddHandler button.Click, AddressOf button_Click  
                button.CommandName = "ExpandCollapse" 
                button.CssClass = IIf((item.Expanded), "rgCollapse""rgExpand")  
                button.ID = "MyExpandCollapseButton" 
 
                If item.OwnerTableView.HierarchyLoadMode = GridChildLoadMode.Client Then 
                    Dim script As String = [String].Format("$find(""{0}"")._toggleExpand(this, event); return false;", item.Parent.Parent.ClientID)  
 
                    button.OnClientClick = script  
                End If 
 
                Dim level As Integer = item.ItemIndexHierarchical.Split(":"c).Length  
                If level > 1 Then 
                    button.Style("margin-left") = level + 10 & "px" 
                End If 
 
                Dim cell As TableCell = (DirectCast(item, GridDataItem))(columnUniqueName)  
                cell.Controls.Add(button)  
                cell.Controls.Add(New LiteralControl("&nbsp;"))  
                cell.Controls.Add(New LiteralControl((DirectCast(item, GridDataItem)).GetDataKeyValue(columnUniqueName).ToString()))  
            End If 
        End If 
    End Sub 
 
    Sub button_Click(ByVal sender As ObjectByVal e As EventArgs)  
        CType(sender, Button).CssClass = IIf((CType(sender, Button).CssClass = "rgExpand"), "rgCollapse""rgExpand")  
    End Sub 

5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 11 Mar 2010, 12:00 PM
Hi Stephen,

Could you try setting the MasterTableView's HierarchlyLoadMode to "ServerBind" and see how it goes. The "ServerOnDemand" load mode (the default one, as in your case) is not supported with the self-referencing hierarchy feature when the grid is bound using a DataSource control.

Regards,
Tsvetoslav
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Tsvetoslav
Telerik team
answered on 11 Mar 2010, 01:11 PM
Hi Stephen,

Just a quick follow-up to the previous response of mine: if you need  edit/insert functionality in the self-referencing grid you need to perform these operations manually in code behind and therefore, the grid should be bound using the NeedDataSource event.

Regards,
Tsvetoslav
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
louis chan
Top achievements
Rank 1
Iron
answered on 12 Mar 2010, 08:26 AM
Yup, it said
productID is neither a DataColumn nor a DataRelation for table DefaultView.

So I need add a needdatasource event here. But What is this purpose for? I have set a datasource in the detail table, why do I need to have coding again?


0
Tsvetoslav
Telerik team
answered on 12 Mar 2010, 01:46 PM
Hi louis,

Unfortunately, this is a limitation of RadGrid's self-referencing hierarchy feature - DataSource controls can be used only for displaying data whereas data manipulation can be achieved only through code-behind.

All the best,
Tsvetoslav
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
louis chan
Top achievements
Rank 1
Iron
answered on 17 Mar 2010, 04:35 AM
Closed in this case
Tags
Grid
Asked by
Stephen Lam
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
louis chan
Top achievements
Rank 1
Iron
Share this question
or