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

Data not populating on expand - several tables at a level

13 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Subhashini
Top achievements
Rank 1
Subhashini asked on 01 Aug 2016, 06:31 PM

I am using the exact example as shown here -http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/hierarchical-grid-types-and-load-modes/several-tables-at-a-level 

I am using SeverOnDemand on Master and DetailTables. 

Using below line in RadGrid1_DetailTableDataBind(), all the rows in the masterTable gets expanded on click of the Expand toggle button.

 RadGrid1.MasterTableView.HierarchyDefaultExpanded = True
e.DetailTableView.HierarchyDefaultExpanded = True

 

How to make the row expand or collapse on toggle sever side?

 

Any help is appreciated. Thanks.

13 Answers, 1 is accepted

Sort by
0
Subhashini
Top achievements
Rank 1
answered on 02 Aug 2016, 07:42 PM
Any one ?
0
Maria Ilieva
Telerik team
answered on 04 Aug 2016, 12:27 PM
Hi,

The following approach works properly for me:
protected void CollapseAllClick(object sender, EventArgs e)
{
RadGrid1.MasterTableView.HierarchyDefaultExpanded = false;
RadGrid1.Rebind();
// If you not used Advance data binding then again Bind // RadGrid1.DataSource = ""; RadGrid1.DataBind();
}
protected void ExpandAllClick(object sender, EventArgs e)
 {
RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
RadGrid1.Rebind();
// If you not used Advance data binding then again Bind // RadGrid1.DataSource = ""; RadGrid1.DataBind();
}

Please check your code and see if any errors appear when this code is executed that might prevent the expand.

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Subhashini
Top achievements
Rank 1
answered on 04 Aug 2016, 02:09 PM

Hi Maria,

Thanks for the reply. I am able to expand - click on a single expand button expands all the rows, as I have the RadGrid1.MasterTableView.HierarchyDefaultExpanded = True
            e.DetailTableView.HierarchyDefaultExpanded = True

in RadGrid1_DetailTableDataBind()

I want to expand a single selected row and collapse the same on clicking the toggle button.

Also, where should I call these funs - CollapseAllClick and ExpandAllClick

 

Thanks.

0
Subhashini
Top achievements
Rank 1
answered on 04 Aug 2016, 02:22 PM

I also tried this demo on Grid - Hierarchy with Templates - http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/hierarchy-with-templates/defaultvb.aspx?show-source=true

I am facing the same problem again, I couldn't toggle expand or collapse (server side).

All i get is the expanded first row on load, as in RadGrid1_PreRender() 

If Not Page.IsPostBack Then
                RadGrid1.MasterTableView.Items(0).Expanded = True
                RadGrid1.MasterTableView.Items(0).ChildItem.FindControl("InnerContainer").Visible = True
End If

0
Subhashini
Top achievements
Rank 1
answered on 04 Aug 2016, 03:15 PM

Okay, I found where I get hit.

This one is  Grid - Hierarchy with tempaltes.

I am using filterCombos in the radgrid. Without filters, eveything works fine. But whenever I filter either the inbuilt filer or the filter combos, radgrid.rebind is called and then the toggle stops working. Any ideas ????

 Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs) Handles RadGrid1.PreRender
        Dim filterExp As String = RadGrid1.MasterTableView.FilterExpression.ToString()
        If filterExp <> "" Then
            filterExp = Replace(filterExp.ToUpper, "[", "")
            filterExp = Replace(filterExp, "]", "")
            RadGrid1.MasterTableView.DataSource = Nothing
            RadGrid1.MasterTableView.Rebind()
        End If      
    End Sub

 Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If TypeOf e.Item Is GridCommandItem Then
            If e.CommandName = "InitShowAll" Then
                RadGrid1.MasterTableView.FilterExpression = String.Empty
                For Each column As GridColumn In RadGrid1.MasterTableView.RenderColumns
                    If TypeOf column Is GridBoundColumn Then
                        Dim boundColumn As GridBoundColumn = TryCast(column, GridBoundColumn)
                        boundColumn.CurrentFilterValue = String.Empty
                    End If
                Next
                RadGrid1.MasterTableView.Rebind()
            End If
        End If
        If e.CommandName = RadGrid.ExpandCollapseCommandName AndAlso TypeOf e.Item Is GridDataItem Then
            DirectCast(e.Item, GridDataItem).ChildItem.FindControl("InnerContainer").Visible = Not e.Item.Expanded
        End If
    End Sub
    Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemCreated
        If TypeOf e.Item Is GridNestedViewItem Then
            e.Item.FindControl("InnerContainer").Visible = DirectCast(e.Item, GridNestedViewItem).ParentItem.Expanded
        End If
    End Sub

 

Thanks

0
Maria Ilieva
Telerik team
answered on 09 Aug 2016, 12:00 PM
Hello,

You can set the RetainExpandStateOnRebind property of the grid, it gets or sets a value indicating if the Expanded property of both hierarchy and group items will be retained after a call to Rebind() or Rebind() method.

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Subhashini
Top achievements
Rank 1
answered on 09 Aug 2016, 02:29 PM

Hi Maria, 

I already have RetainExpandStateOnRebind="true"  in the parent RadGrid and also in the Radpageview radGrids. But it is not working. I have attached the before and after filtering screen shots. You can see the toggle icon is shown as expanded but there is no grid visible. I even tried closing the row and expanding it again. Still nothing.

<MasterTableView CommandItemDisplay="Top" DataKeyNames="TASK_ID" CssClass="table" ClientDataKeyNames="TASK_ID, STATUS" TableLayout="Auto" HorizontalAlign="NotSet" AutoGenerateColumns="false" RetainExpandStateOnRebind="true" HierarchyLoadMode="ServerOnDemand" AllowFilteringByColumn="true" AllowMultiColumnSorting="True">

In Grid PreRender, I am calling the Rebind().

 Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs) Handles RadGrid1.PreRender
        Dim filterExp As String = RadGrid1.MasterTableView.FilterExpression.ToString()
        If filterExp <> "" Then
            filterExp = Replace(filterExp.ToUpper, "[", "")
            filterExp = Replace(filterExp, "]", "")
            RadGrid1.MasterTableView.DataSource = Nothing
            RadGrid1.MasterTableView.Rebind()
        End If
End Sub

Thanks.

0
Subhashini
Top achievements
Rank 1
answered on 09 Aug 2016, 08:54 PM

I have RadGrid1_NeedDataSource() for the main grid, and declarative binding for the nested radgrids. Where should rebind? 

Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemCreated

        'BELOW LINES: if comment these lines - filter works for outer grid and not for inner grid; if uncommented - filter works for inner and not for outer grid. What piece of code am I missing ?
        If TypeOf e.Item Is GridNestedViewItem Then
            e.Item.FindControl("InnerContainer").Visible = DirectCast(e.Item, GridNestedViewItem).ParentItem.Expanded
        End If
    End Sub

Thanks.

0
Subhashini
Top achievements
Rank 1
answered on 10 Aug 2016, 02:53 PM

Looks like same issue that was discussed here but i couldn't find a solution yet  -http://www.telerik.com/forums/nestedviewtemplate-and-filtering

0
Subhashini
Top achievements
Rank 1
answered on 10 Aug 2016, 04:51 PM

Update:

The parent filter works.  I removed the Parent RadGrid1_ItemCreated() and  I updated the Parent Prerender, but I couldn't perform expand/filter/sort in the inner grid after filtering the Parent grid.

Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs) Handles RadGrid1.PreRender
        Dim filterExp As String = RadGrid1.MasterTableView.FilterExpression.ToString()
        If filterExp <> "" Then
            filterExp = Replace(filterExp.ToUpper, "[", "")
            filterExp = Replace(filterExp, "]", "")
            RadGrid1.MasterTableView.DataSource = Nothing

            LoopHierarchyRecursive((RadGrid1.MasterTableView))         
        End If    
    End Sub

 Protected Sub LoopHierarchyRecursive(ByVal gridTableView As GridTableView)
        gridTableView.Rebind()

        For Each nestedViewItem As GridNestedViewItem In gridTableView.GetItems(GridItemType.NestedView)
            nestedViewItem.FindControl("InnerContainer").Visible = DirectCast(nestedViewItem, GridNestedViewItem).ParentItem.Expanded 
            If nestedViewItem.NestedTableViews.Length > 0 Then
                LoopHierarchyRecursive(nestedViewItem.NestedTableViews(0))
            End If
        Next
    End Sub

 

This is so frustrating.

It would be really helpful if i can get a sample code for Grid - Hierarchy with Templates , with filters in both outer and inner grids.

0
Accepted
Maria Ilieva
Telerik team
answered on 12 Aug 2016, 01:50 PM
Hello,

You should not call Rebind() or setting DataSource to Nothing in the PreRender event as this is causing recreating all grid items, which is returning them to their initial state. In this case all items are collapsed.

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Subhashini
Top achievements
Rank 1
answered on 19 Aug 2016, 07:40 PM

That worked(for now). Thanks Maria.

 

0
Maria Ilieva
Telerik team
answered on 24 Aug 2016, 12:11 PM
Hello Subhashini,

I'm glad that the provided solution works for you. Do not hesitate to contact us in case further assistance is needed.

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Subhashini
Top achievements
Rank 1
Answers by
Subhashini
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or