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

Collapse nested table rows using HideExpandColumnRecursive method

1 Answer 460 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron Jessen
Top achievements
Rank 1
Aaron Jessen asked on 06 Aug 2009, 06:33 PM

The following code (called from RadGrid_PreRender) will iterate through a radgrid (and 3 nested tables) and hide the expand button if the row has no child records. I pieced this together from samples on this forum.

1) The MasterTableView is first populated by a call to NeedDataSource
2) The rows for the related nested tables are called by the DetailTableDataBind method
3) HierarchyLoadMode="ServerOnDemand" for all 4 tables ("Client" is not acceptable due to number of records)

 

 

 

Now, the last 3 lines of code (below, currently commented out) will collapse the MasterTableView nicely. However, upon expanding a row from that MasterTableView, the nested tables within are all expanded - not collapsed - as I need them to be. 

I have exhausted so many possibilities, so I finally posted this here. Note: This is not a question of how to hide the expand column (as is discussed in previous posts). Rather, it is a matter of making already collapsed tables STAY collapsed when the MasterTableView is expanded.

I suspect the problem lies within the DetailTableDataBind being called by ServerOnDemand after the MasterTableView row is clicked (thusly, repopulating the tables and overwriting any hiding/collapsing that has already been perfomed). Basically, I really need to know how to call "HideExpandColumnRecursive" on NESTED detail tables after they are created (which happens after a MasterTableView has been expanded). Complicated, I know. Any help would be greatly appreciated.

 

Protected

 

Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs)

 

 

If Not IsPostBack Then

 

 

 

HideExpandColumnRecursive(RadGrid1.MasterTableView)

 

 

End If

 

 

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

 

 

If nestedView.Items.Count = 0 Then

 

 

Dim cell As TableCell = nestedView.ParentItem("ExpandColumn")

 

 

Dim expandCollapseButton As Button = CType(cell.Controls(0), Button)

 

expandCollapseButton.Visible =

False

 

nestedViewItem.Visible =

False

 

 

End If

 

 

If nestedView.HasDetailTables Then

 

HideExpandColumnRecursive(nestedView)

 

End If

 

 

Next

 

 

Next

 

 

'For Each item As GridDataItem In RadGrid1.MasterTableView.Items

 

 

' item.Expanded = False

 

 

'Next

 

 

End Sub

 

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 10 Aug 2009, 08:23 AM
Hi Aaron,

What I understood from your post and the support ticket is that you want to achieve look of the grid like this one. So I suggest that you follow closely the demo and read these articles:
Traversing detail tables/items in Telerik RadGrid
Single expand in hierarchical grid
Hiding expand/collapse images when no records

I hope this gets you started properly.

Kind regards,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Aaron Jessen
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or