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

Hide expand and collapse images in nested tables

11 Answers 251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 22 Sep 2009, 11:16 PM
I'm sure someone has figured this out by now. I'm at my wits end trying to get it to work. Very little help in the documentation and forums on how to do this.

I have a Grid with about 4 nested tables:


I've tried this but it will not work on any nested DetailTables:

Public Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)
        Dim test As String = Nothing
        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")
                    cell.Controls(0).Visible = False
                    nestedViewItem.Visible = False
                End If
                If nestedView.HasDetailTables Then
                    HideExpandColumnRecursive(nestedView)
                End If
            Next
        Next
    End Sub

I understand the I have to do a recursive search and set visible to false for all the detailTables as above but I cant figure out how to do this. I read the online help and still cant get it to work. Does anyone have an example on how to hide the expand/collapse image in a multi nested table scenario?

Thank you for your help. Shouldn't this be built in???



<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSourceParent"
            GridLines="None" Skin="Telerik" ShowGroupPanel="True">
            <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSourceParent" DataKeyNames="PART_ID" NoDetailRecordsText="" HierarchyLoadMode="ServerBind">
                <DetailTables>
                    <telerik:GridTableView runat="server" DataKeyNames="PART_ID" DataSourceID="sqlDataSourceSub"
                        GridLines="Both" NoDetailRecordsText="">
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <DetailTables>
                            <telerik:GridTableView runat="server" DataSourceID="sqlDataSourceSub0"
                                DataKeyNames="PART_ID" NoDetailRecordsText="">
                                <DetailTables>
                                    <telerik:GridTableView runat="server" DataSourceID="sqlDataSourceSub1"
                                        DataKeyNames="PART_ID" NoDetailRecordsText="">
                                        <DetailTables>
                                            <telerik:GridTableView runat="server" DataKeyNames="PART_ID"
                                                DataSourceID="SqlDataSourceSub2">
                                                <ParentTableRelation>
                                                    <telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />
                                                </ParentTableRelation>
                                                <RowIndicatorColumn>
                                                    <HeaderStyle Width="20px" />
                                                </RowIndicatorColumn>
                                                <ExpandCollapseColumn>
                                                    <HeaderStyle Width="20px" />
                                                </ExpandCollapseColumn>
                                            </telerik:GridTableView>
                                        </DetailTables>
                                        <ParentTableRelation>
                                            <telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />
                                        </ParentTableRelation>
                                        <RowIndicatorColumn>
                                            <HeaderStyle Width="20px" />
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn Visible="True">
                                        </ExpandCollapseColumn>
                                    </telerik:GridTableView>
                                </DetailTables>
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />
                                </ParentTableRelation>
                                <RowIndicatorColumn>
                                    <HeaderStyle Width="20px" />
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn Visible="True">
                                    <HeaderStyle Width="20px" />
                                </ExpandCollapseColumn>
                            </telerik:GridTableView>
                        </DetailTables>
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />
                        </ParentTableRelation>
                        <ExpandCollapseColumn Visible="True">
                        </ExpandCollapseColumn>
                    </telerik:GridTableView>
                </DetailTables>
                <ExpandCollapseColumn Visible="True">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridBoundColumn DataField="PART_ID" HeaderText="PART_ID" SortExpression="PART_ID"
                        UniqueName="PART_ID">
                    </telerik:GridBoundColumn>
                    
                    <telerik:GridBoundColumn DataField="BASE_ID" HeaderText="BASE_ID" SortExpression="BASE_ID"
                        UniqueName="BASE_ID">
                    </telerik:GridBoundColumn>
                    
                    <telerik:GridBoundColumn DataField="DESCRIPTION" HeaderText="DESCRIPTION" SortExpression="DESCRIPTION"
                        UniqueName="DESCRIPTION">
                    </telerik:GridBoundColumn>
                    
                     <telerik:GridBoundColumn DataField="QTY_ON_HAND" HeaderText="QTY_ON_HAND" SortExpression="QTY_ON_HAND"
                        UniqueName="QTY_ON_HAND">
                    </telerik:GridBoundColumn>
                    
                </Columns>
            </MasterTableView>
            <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True"
                ReorderColumnsOnClient="True">
            </ClientSettings>
        </telerik:RadGrid>

11 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 23 Sep 2009, 01:54 AM
Hello Larry-

Your code looks correct. Two things to check:

  1. Make sure you are calling this code in the Grid's PreRender event. That is the proper point in the Grid lifecycle to hide/show the expand collapse images.
  2. Make sure your nested data views have bound data before this recursive loop runs. This loop's logic will check the nested views of each "parent view" for a record count > 0. If the row count is <= 0, then the expand/collapse image should be hidden.

For your reference (and for those that follow looking for help), here are two articles in the Telerik.com help docs outlining the code needed for this scenario:


I know your code already comes from one of these articles (the 2nd), and it looks right based on your post.

What behavior are you observing? Are all nested views expanded and the expand/collapse images are never being hidden? If you debug your application and put a breakpoint in the "HideExpandColumnRecursive" method, does your code properly run and try to hide the column image? That info should help additional debugging.

Hope that helps!
-Todd
0
Michele
Top achievements
Rank 2
answered on 23 Sep 2009, 12:48 PM
Todd, Thank you for your reply.

I created this project based off the telerik training video for nested tables. The database I'm using does not have data under every expand image, so I need to hide this. Without hiding the expand/collapse image, we cannot tell which column has additional data and which don't, almost making the data useless. I have done an easy basic nested table grid with nothing else to complicate things.

As you can see in my previous post I have nested tables based off ParentTableRelationship as in the video. Based off this generic implimentation I need to hide the expand/collapse image for fields that do not contain any data or additional parentTableRelationship.

When I call HideExpandColumnRecursive it hides all the expand images even if there is addition Data / DetailsTable to be viewed. Its not checking if there is more data past the second level. I have up to 6 nested tables.

If you create create a grid with nested tables 3 deep or more you can see what is happening.

Todd you mentioned;  2. Make sure your nested data views have bound data before this recursive loop runs. This loop's logic will check the nested views of each "parent view" for a record count > 0. If the row count is <= 0, then the expand/collapse image should be hidden. I'm doing the nested tables as directed by Telerik so I'm not sure if they have bound data before the recursive loops runs? Do they have bound data?

Please can someone help.. 

Thank you.


ALL MY CODE ----

 

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSourceParent"

 

 

GridLines="None" Skin="Telerik" ShowGroupPanel="True">

 

 

<MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSourceParent" DataKeyNames="PART_ID" NoDetailRecordsText="" HierarchyLoadMode="ServerBind">

 

 

<DetailTables>

 

 

<telerik:GridTableView runat="server" DataKeyNames="PART_ID" DataSourceID="sqlDataSourceSub"

 

 

GridLines="Both" NoDetailRecordsText="">

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

<DetailTables>

 

 

<telerik:GridTableView runat="server" DataSourceID="sqlDataSourceSub0"

 

 

DataKeyNames="PART_ID" NoDetailRecordsText="">

 

 

<DetailTables>

 

 

<telerik:GridTableView runat="server" DataSourceID="sqlDataSourceSub1"

 

 

DataKeyNames="PART_ID" NoDetailRecordsText="">

 

 

<DetailTables>

 

 

<telerik:GridTableView runat="server" DataKeyNames="PART_ID"

 

 

DataSourceID="SqlDataSourceSub2">

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />

 

 

</ParentTableRelation>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</ExpandCollapseColumn>

 

 

</telerik:GridTableView>

 

 

</DetailTables>

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />

 

 

</ParentTableRelation>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn Visible="True">

 

 

</ExpandCollapseColumn>

 

 

</telerik:GridTableView>

 

 

</DetailTables>

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />

 

 

</ParentTableRelation>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn Visible="True">

 

 

<HeaderStyle Width="20px" />

 

 

</ExpandCollapseColumn>

 

 

</telerik:GridTableView>

 

 

</DetailTables>

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields DetailKeyField="PART_ID" MasterKeyField="PART_ID" />

 

 

</ParentTableRelation>

 

 

<ExpandCollapseColumn Visible="True">

 

 

</ExpandCollapseColumn>

 

 

</telerik:GridTableView>

 

 

</DetailTables>

 

 

<ExpandCollapseColumn Visible="True">

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="PART_ID" HeaderText="PART_ID" SortExpression="PART_ID"

 

 

UniqueName="PART_ID">

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn DataField="BASE_ID" HeaderText="BASE_ID" SortExpression="BASE_ID"

 

 

UniqueName="BASE_ID">

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn DataField="DESCRIPTION" HeaderText="DESCRIPTION" SortExpression="DESCRIPTION"

 

 

UniqueName="DESCRIPTION">

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn DataField="QTY_ON_HAND" HeaderText="QTY_ON_HAND" SortExpression="QTY_ON_HAND"

 

 

UniqueName="QTY_ON_HAND">

 

 

</telerik:GridBoundColumn>

 

 

 

</Columns>

 

 

</MasterTableView>

 

 

<ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True"

 

 

ReorderColumnsOnClient="True">

 

 

</ClientSettings>

 

 

</telerik:RadGrid>

 

 

<br />

 

 

</div>

 

 

<asp:SqlDataSource ID="SqlDataSourceParent" runat="server" ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT PART_ID, WORK_ORDER.TYPE, WORK_ORDER.BASE_ID, PART.DESCRIPTION, PART.QTY_ON_HAND, PART.QTY_ON_ORDER

 

FROM WORK_ORDER INNER JOIN

PART ON WORK_ORDER.PART_ID = PART.ID

WHERE ([PART_ID] = @PART_ID AND WORK_ORDER.STATUS = 'R')">

 

<SelectParameters>

 

 

<asp:ControlParameter ControlID="txtPartId" Name="PART_ID" PropertyName="Text" Type="String" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSourceSub" runat="server" ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT WORK_ORDER.BASE_ID AS Work_Order, WORK_ORDER.PART_ID AS WO_PART_ID, REQUIREMENT.PART_ID, PART.DESCRIPTION, PART.QTY_ON_HAND, PART.QTY_ON_ORDER

 

FROM WORK_ORDER INNER JOIN

REQUIREMENT INNER JOIN

PART ON REQUIREMENT.PART_ID = PART.ID ON WORK_ORDER.BASE_ID = REQUIREMENT.WORKORDER_BASE_ID

WHERE (REQUIREMENT.STATUS = 'R') AND (WORK_ORDER.PART_ID = @PART_ID)">

 

<SelectParameters>

 

 

<asp:SessionParameter Name="PART_ID" SessionField="PART_ID" Type="String" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSourceSub0" runat="server" ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT dbo.WORK_ORDER.BASE_ID AS Work_Order, dbo.WORK_ORDER.PART_ID AS WO_PART_ID, PART_1.DESCRIPTION AS WO_DESCRIPTION,

 

dbo.REQUIREMENT.PART_ID, dbo.PART.DESCRIPTION, PART.QTY_ON_HAND, PART.QTY_ON_ORDER

FROM dbo.WORK_ORDER INNER JOIN

dbo.PART AS PART_1 ON dbo.WORK_ORDER.PART_ID = PART_1.ID INNER JOIN

dbo.REQUIREMENT INNER JOIN

dbo.PART ON dbo.REQUIREMENT.PART_ID = dbo.PART.ID ON dbo.WORK_ORDER.BASE_ID = dbo.REQUIREMENT.WORKORDER_BASE_ID

WHERE dbo.WORK_ORDER.PART_ID = @PART_ID">

 

<SelectParameters>

 

 

<asp:SessionParameter Name="PART_ID" SessionField="PART_ID" Type="String" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSourceSub1" runat="server" ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT dbo.WORK_ORDER.BASE_ID AS Work_Order, dbo.WORK_ORDER.PART_ID AS WO_PART_ID, PART_1.DESCRIPTION AS WO_DESCRIPTION,

 

dbo.REQUIREMENT.PART_ID, dbo.PART.DESCRIPTION, PART.QTY_ON_HAND, PART.QTY_ON_ORDER

FROM dbo.WORK_ORDER INNER JOIN

dbo.PART AS PART_1 ON dbo.WORK_ORDER.PART_ID = PART_1.ID INNER JOIN

dbo.REQUIREMENT INNER JOIN

dbo.PART ON dbo.REQUIREMENT.PART_ID = dbo.PART.ID ON dbo.WORK_ORDER.BASE_ID = dbo.REQUIREMENT.WORKORDER_BASE_ID

WHERE dbo.WORK_ORDER.PART_ID = @PART_ID">

 

<SelectParameters>

 

 

<asp:SessionParameter Name="PART_ID" SessionField="PART_ID" Type="String" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSourceSub2" runat="server" ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT dbo.WORK_ORDER.BASE_ID AS Work_Order, dbo.WORK_ORDER.PART_ID AS WO_PART_ID, PART_1.DESCRIPTION AS WO_DESCRIPTION,

 

dbo.REQUIREMENT.PART_ID, dbo.PART.DESCRIPTION, PART.QTY_ON_HAND, PART.QTY_ON_ORDER

FROM dbo.WORK_ORDER INNER JOIN

dbo.PART AS PART_1 ON dbo.WORK_ORDER.PART_ID = PART_1.ID INNER JOIN

dbo.REQUIREMENT INNER JOIN

dbo.PART ON dbo.REQUIREMENT.PART_ID = dbo.PART.ID ON dbo.WORK_ORDER.BASE_ID = dbo.REQUIREMENT.WORKORDER_BASE_ID

WHERE dbo.WORK_ORDER.PART_ID = @PART_ID">

 

<SelectParameters>

 

 

<asp:SessionParameter Name="PART_ID" SessionField="PART_ID" Type="String" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSourceSub3" runat="server" ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT dbo.WORK_ORDER.BASE_ID AS Work_Order, dbo.WORK_ORDER.PART_ID AS WO_PART_ID, PART_1.DESCRIPTION AS WO_DESCRIPTION,

 

dbo.REQUIREMENT.PART_ID, dbo.PART.DESCRIPTION, PART.QTY_ON_HAND, PART.QTY_ON_ORDER

FROM dbo.WORK_ORDER INNER JOIN

dbo.PART AS PART_1 ON dbo.WORK_ORDER.PART_ID = PART_1.ID INNER JOIN

dbo.REQUIREMENT INNER JOIN

dbo.PART ON dbo.REQUIREMENT.PART_ID = dbo.PART.ID ON dbo.WORK_ORDER.BASE_ID = dbo.REQUIREMENT.WORKORDER_BASE_ID

WHERE dbo.WORK_ORDER.PART_ID = @PART_ID">

 

<SelectParameters>

 

 

<asp:SessionParameter Name="PART_ID" SessionField="PART_ID" Type="String" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSourceSub4" runat="server" ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT dbo.WORK_ORDER.BASE_ID AS Work_Order, dbo.WORK_ORDER.PART_ID AS WO_PART_ID, PART_1.DESCRIPTION AS WO_DESCRIPTION,

 

dbo.REQUIREMENT.PART_ID, dbo.PART.DESCRIPTION, PART.QTY_ON_HAND, PART.QTY_ON_ORDER

FROM dbo.WORK_ORDER INNER JOIN

dbo.PART AS PART_1 ON dbo.WORK_ORDER.PART_ID = PART_1.ID INNER JOIN

dbo.REQUIREMENT INNER JOIN

dbo.PART ON dbo.REQUIREMENT.PART_ID = dbo.PART.ID ON dbo.WORK_ORDER.BASE_ID = dbo.REQUIREMENT.WORKORDER_BASE_ID

WHERE dbo.WORK_ORDER.PART_ID = @PART_ID">

 

<SelectParameters>

 

 

<asp:SessionParameter Name="PART_ID" SessionField="PART_ID" Type="String" />

 

 

</SelectParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="SqlDataSourceShop_Resource" runat="server"

 

 

ConnectionString="<%$ ConnectionStrings:PSGINEWConnectionString %>"

 

 

SelectCommand="SELECT [ID], [DESCRIPTION] FROM [SHOP_RESOURCE]">

 

 

</asp:SqlDataSource>

 

 

<br />

 

 

<br />

 

 

<telerik:RadAjaxManager runat="server">

 

 

<AjaxSettings>

 

 

<telerik:AjaxSetting AjaxControlID="RadGrid1">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1"

 

 

LoadingPanelID="RadAjaxLoadingPanel1" />

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

</AjaxSettings>

 

 

</telerik:RadAjaxManager>

 

 

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server"

 

 

Skin="Default">

 

 

</telerik:RadAjaxLoadingPanel>

 



Private

 

Sub RemoveExpandIconWhenNoRecords(ByVal view As GridTableView)

 

 

Dim item As GridItem

 

 

If (view.Controls.Count > 0) Then

 

 

For Each item In view.Controls(0).Controls

 

 

If TypeOf item Is GridNestedViewItem Then

 

 

Dim nestedViewItem As GridNestedViewItem = CType(item, GridNestedViewItem)

 

 

If nestedViewItem.NestedTableViews(0).Items.Count = 0 Then

 

 

Dim cell As TableCell = nestedViewItem.NestedTableViews(0).ParentItem("ExpandColumn")

 

cell.Controls(0).Visible =

False

 

nestedViewItem.Visible =

False

 

 

Else

 

RemoveExpandIconWhenNoRecords(nestedViewItem.NestedTableViews(0))

 

End If

 

 

End If

 

 

Next item

 

 

End If

 

 

End Sub

 

 

Public Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)

 

 

Dim test As String = Nothing

 

 

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")

 

cell.Controls(0).Visible =

False

 

nestedViewItem.Visible =

False

 

 

End If

 

 

If nestedView.HasDetailTables Then

 

HideExpandColumnRecursive(nestedView)

 

End If

 

 

Next

 

 

Next

 

 

End Sub

 

 

Protected Sub RadGrid1_PreRender1(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender

 

RemoveExpandIconWhenNoRecords(RadGrid1.MasterTableView)

 

'HideExpandColumnRecursive(RadGrid1.MasterTableView)

 

 

End Sub

 


0
Michele
Top achievements
Rank 2
answered on 25 Sep 2009, 12:14 PM
Any Ideas? Anyone? Desperate here...
0
Todd Anglin
Top achievements
Rank 2
answered on 25 Sep 2009, 02:20 PM
Hello Larry-

Sorry for the delayed reply - you provided a lot of code to look at and I'm actually still confused by your situation. Let me see if I can better understand. The questions that remain for me:


From the way you've described your setup, it sounds like things are behaving as expected. If the 2nd level of a multi-level hierarchy has no data, there should be no expand collapse. The grid will not analyze past the 2nd level because, in theory, if the data is truly hierarchal, there shouldn't be data past an empty 2nd level.

If you can better help me understand the scenario you want to achieve, I think that will help me provide better code direction. I hope I can help.

-Todd
0
Michele
Top achievements
Rank 2
answered on 25 Sep 2009, 07:08 PM

Todd,

Thanks again for your help I really appreciate it. _ My boss is torturing me on this.. lol

To answer your question, Am I using Several tables at the same level - NO. I have 1 gridview and several separate nested tables. I'm making these nested tables by creating several datasources. I then add a details table for each datasource and set the ParentTableRelationship for them. That’s about it.. Very simple implementation.

This image shows the output without calling HideExpandColumnRecursive.
http://www.sure-trac.com/untitled.JPG

After calling HideExpandColumnRecursive I get this.
http://www.sure-trac.com/expandgone.JPG

I'm using nested tables each with their own datasource. The table that I'm working on is here.
http://www.sure-trac.com/table.JPG

My code is here.
http://www.sure-trac.com/CardinalTree.zip


As you can see in the images not all work orders have data, but some have several nested results. Being able to hide the ones that do not have additional nested data will allow them to know which ones to drill down to..

Again, Thank you for your help and sorry if this is confusing.

Larry



0
Todd Anglin
Top achievements
Rank 2
answered on 28 Sep 2009, 04:02 PM
Thanks for the extra details and screenshots, Larry. That helps me understand what you're doing.

I also took a look at your code, and again everything seems to be on the "right track." Since the code obviously doesn't include your data, I can't do local debugging, but I'd encourage you to step your project. Specifically, with the VS debugger, put a breakpoint on this line in your code behind (somewhere around line 63):

If nestedView.Items.Count = 0 Then

Then, run your page and inspect the value of the nestedView.Items.Count for tables that should/shouldn't have their expand images hidden. That will reveal whether or not the data is correctly available in your project. In general, I think debugging your app by stepping it with the debugger should help you quickly zero-in on the "tweaks" you can make to your logic to correctly hide the expand / collapse images. You know you have code that accurately hides the images, you just need to refine which items the code gets applied to.

Does that make sense? Try the debugging and let me know if you learn anything.

-Todd
0
Michele
Top achievements
Rank 2
answered on 29 Sep 2009, 02:39 PM
Todd,

I didn't realize this was going to big such a big issue to resolve. I'm not sure how others got this figured out. But once a solution is found I think it should be posted in the help files. I'm sure others want to hide the expand/collapse images in nested tables 3+ deep.
I looked at it again and I still can't figure out why it says that there is no nested data. Below is the project with the database. I checked the code at the break point suggested but its saying that there is 0 sub menues, when clearly there is not.

[Moderator Edit - Link removed]

Test data:
Main Work Order = 30583
Expand- PART_ID = 30594
Expand2- PART_ID = 30539

I'm with another company and I'm trying to show them the value of Telerik in rapid development. I thought this was going to be an easly Telerik solution to demonstrate but It seems to have back fired.

Once this is solved I have a few other similar implimentations that should makeup for the problems I've been having, and show them that Telerik is a good solution..

Todd...
Thanks again for your help and I hope others find value in this solution.
0
Todd Anglin
Top achievements
Rank 2
answered on 29 Sep 2009, 03:09 PM
Thanks for the project, Larry.

The answer to your problem is actually very simple once I saw what was happening in your situation. You simply need to set the HierarchyLoadMode for all of your GridTableView objects to "ServerBind" and everything will behave the way you expect.

<telerik:GridTableView runat="server" HierarchyLoadMode="ServerBind" ...

You had the property correctly set on your top level GridTableView, but it was unset on the child views. That in-turn is why the data was not being loaded for your nested levels at the right time for HideExpandColumnRecursive to work. If you set this property and enable the HideExpandColumnRecursive function on PreRender, you should have exactly what you need.

Hope that helps.

-Todd

[SIDE NOTE: I removed the link to your project in your previous post because it contained a licensed version of the RadControls. Please be very careful when sharing files that contain your purchased Telerik assemblies. In the future, if you need to share files, it is best to open a Support Ticket and attach your files there.]
0
Ted
Top achievements
Rank 1
answered on 19 Mar 2010, 03:38 PM
I just wanted to say thanks to Todd as I ran into this same issue and setting the load mode fixed my issue.

I will agree that it would be a nice to see a property that we could just set true or false to show the expand image if there are no child records.

0
Roger
Top achievements
Rank 1
answered on 15 Mar 2012, 02:24 PM
Both of these links shown in an earlier post are broken.


Can someone please point me to a working example of how to hide the Expand Arrow when there are no child records?

thanks
0
Princy
Top achievements
Rank 2
answered on 15 Mar 2012, 02:35 PM
Hello Roger,

Try the following code in PreRender event.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    HideExpandColumnRecursive(RadGrid1.MasterTableView);
}
public void HideExpandColumnRecursive(GridTableView tableView)
{
    GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
    {
        foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
        {
            if (nestedView.Items.Count == 0)
            {
                TableCell cell = nestedView.ParentItem["ExpandColumn"];
                cell.Controls[0].Visible = false;
                cell.Text = " ";
                nestedViewItem.Visible = false;
            }
            if (nestedView.HasDetailTables)
            {
                HideExpandColumnRecursive(nestedView);
            }
        }
    }
}

Thanks,
Princy.


Tags
Grid
Asked by
Michele
Top achievements
Rank 2
Answers by
Todd Anglin
Top achievements
Rank 2
Michele
Top achievements
Rank 2
Ted
Top achievements
Rank 1
Roger
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or