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

RadGrid DetailTables hiding the expand column

1 Answer 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bowlsey
Top achievements
Rank 1
Bowlsey asked on 23 Sep 2010, 11:01 AM
Hi 

I've taken an example from the demo's site, to hide the expand button and add it into an existing column alongside the text.
using this code which is run from RadGrid1_ItemDataBound

public void CreateExpandCollapseButton(GridItem item, string columnUniqueName, String ButtonColumn)
        {
            if (item is GridDataItem)
            {
                if (item.FindControl("MyExpandCollapseButton") == null)
                {
                    Button button = new Button();
                    button.Click += new EventHandler(button_Click);
                    button.CommandName = "ExpandCollapse";
                    button.CssClass = (item.Expanded) ? "rgCollapse" : "rgExpand";
                    button.ID = "MyExpandCollapseButton";
 
                    if (item.OwnerTableView.HierarchyLoadMode == GridChildLoadMode.Client)
                    {
                        string script = String.Format(@"$find(""{0}"")._toggleExpand(this, event); return false;", item.Parent.Parent.ClientID);
 
                        button.OnClientClick = script;
                    }
 
                    int level = item.ItemIndexHierarchical.Split(':').Length;
                    if (level > 1)
                    {
                        button.Style["margin-left"] = level * 5 + "px";
                    }
 
                    TableCell cell = ((GridDataItem)item)[ButtonColumn];
                    cell.Controls.Add(button);
                    cell.Controls.Add(new LiteralControl(" "));
                    cell.Controls.Add(new LiteralControl(((GridDataItem)item).GetDataKeyValue(ButtonColumn).ToString()));
                }
            }
        }

But this code was for the selfHierarchy demo.  I have 6 inner details tables each within each other like so

<telerik:RadGrid ID="RadGrid1" OnPreRender="RadGrid1_PreRender" OnItemDataBound="RadGrid1_ItemDataBound" ShowStatusBar="true" Skin="Office2007" OnItemCreated="RadGrid1_ItemCreated"
            runat="server" AutoGenerateColumns="true" AllowSorting="true" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="False" OnColumnCreated="RadGrid1_ColumnCreated"
            AllowPaging="false" GridLines="None">
            <MasterTableView DataKeyNames="HierarchyID, Link, Name" AllowMultiColumnSorting="True" AutoGenerateColumns="true" HorizontalAlign="Right">
            <DetailTables>
            <telerik:GridTableView DataKeyNames="HierarchyID, Link, Name" Name="2" Width="100%" runat="server" AutoGenerateColumns="true" HorizontalAlign="Right">
            <ParentTableRelation>
                 <telerik:GridRelationFields DetailKeyField="Link" MasterKeyField="HierarchyID" />
            </ParentTableRelation>
            <DetailTables>
                <telerik:GridTableView DataKeyNames="HierarchyID, Link, Name" Name="3" Width="100%" runat="server" AutoGenerateColumns="true" HorizontalAlign="Right">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="Link" MasterKeyField="HierarchyID" />
                    </ParentTableRelation>
                    <DetailTables>
                    <telerik:GridTableView DataKeyNames="HierarchyID, Link, Name" Name="4" Width="100%" runat="server" AutoGenerateColumns="true" HorizontalAlign="Right">
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="Link" MasterKeyField="HierarchyID" />
                        </ParentTableRelation>
                        <DetailTables>
                        <telerik:GridTableView DataKeyNames="HierarchyID, Link, Name" Name="5" Width="100%" runat="server" AutoGenerateColumns="true" HorizontalAlign="Right">
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="Link" MasterKeyField="HierarchyID" />
                            </ParentTableRelation>
                            <DetailTables>
                            <telerik:GridTableView DataKeyNames="HierarchyID, Link, Name" Name="6" Width="100%" runat="server" AutoGenerateColumns="true" HorizontalAlign="Right">
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="Link" MasterKeyField="HierarchyID" />
                                </ParentTableRelation>
                            </telerik:GridTableView>
                            </DetailTables>
                        </telerik:GridTableView>
                        </DetailTables>
                    </telerik:GridTableView>
                    </DetailTables>
                </telerik:GridTableView>
                </DetailTables>
            </telerik:GridTableView>
            </DetailTables>
        </MasterTableView>
        </telerik:RadGrid>

So  i need to know how i can rewrite the CreateExpandCollapseButton for the detailtables and how to hide the default expand column within the details table.
Assuming something like this

            if (e.Column is GridExpandColumn)
            {
                e.Column.Visible = false;
            }

Thanks for any assistance.

Matt

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 Sep 2010, 08:47 AM
Hi Bowlsey,

I suggest that you examine this help article, which elaborates on how to hide expand/collapse image and see if it helps to achieve your goal.

Additionally, in order to hide the expand/collapse images in multiple nested levels, you will need to perform a recursive loop through each table in depth. How to traverse the grid items in such manner you can learn from this topic.

Greetings,

Pavlina
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
Tags
Grid
Asked by
Bowlsey
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or