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

export alignment with heirarchial grid

1 Answer 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MBEN
Top achievements
Rank 1
Veteran
MBEN asked on 06 Jan 2012, 10:15 PM
I have a parent child heirarchial grid but I am having issues when I export the grid.

The master records don't start from the first column and seems to be in the end.
I would like the parent records to start from column A and the child records to be indented inside.

Attached is a screenshot and my grid code:

.aspx
 
<telerik:RadGrid ID="rgBeneficiary" runat="server" GridLines="Vertical" AllowPaging="true"
                    AllowAutomaticUpdates="false" AllowAutomaticInserts="false" AutoGenerateColumns="False"
                    EnableLinqExpressions="false" AllowSorting="true" AllowAutomaticDeletes="false"
                    Skin="MBen" EnableEmbeddedSkins="false" DataSourceID="_dataSrcBeneficiaries"
                    AllowCustomPaging="false" AllowFilteringByColumn="true" Width="100%" OnPreRender="rgBeneficiary_PreRender"
                    OnItemCommand="rgBeneficiary_ItemCommand" OnItemCreated="rgBeneficiary_ItemCreated"
                    PageSize="15" ImagesPath="../../App_Themes/MBen/Grid">
                    <MasterTableView TableLayout="Fixed" HierarchyDefaultExpanded="false"
                        HierarchyLoadMode="ServerBind" CommandItemDisplay="Top"
                        ExpandCollapseColumn-CollapseImageUrl="../../App_Themes/MBen/Grid/Collapse.gif"
                        HorizontalAlign="Right" ExpandCollapseColumn-Display="false" RowIndicatorColumn-Display="false"
                        ExpandCollapseColumn-ExpandImageUrl="../../App_Themes/MBen/Grid/Expand.gif">
                        <CommandItemSettings ShowRefreshButton="false" ShowExportToExcelButton="true" ExportToExcelText=""
                            ExportToCsvText="" ExportToPdfText="" ExportToWordText="" ShowExportToPdfButton="true"
                            ShowExportToWordButton="true" ShowExportToCsvButton="true" ShowAddNewRecordButton="false" />
                       <Columns>
                            <telerik:GridTemplateColumn UniqueName="TemplateColumn" AllowFiltering="false" HeaderStyle-Width="3%">
                                <ItemTemplate>
                                    <asp:ImageButton ID="btnCollapse" runat="server" CommandName="ExpandCollapse" ImageUrl="~/App_Themes/MBen/Grid/Collapse.gif"
                                        ToolTip="Collapse" Visible="False " />
                                    <asp:ImageButton ID="btnExpand" runat="server" CommandName="ExpandCollapse" ImageUrl="~/App_Themes/MBen/Grid/Expand.gif"
                                        ToolTip="Expand" />
                                </ItemTemplate>
                                <HeaderTemplate>
                                    <asp:ImageButton ID="ExpandAll" runat="server" CommandName="ExpandAll" ImageUrl="~/App_Themes/MBen/Grid/Expand.gif"
                                        ToolTip="ExpandAll" />
                                    <asp:ImageButton ID="CollapseAll" runat="server" CommandName="CollapseAll" Visible="False"
                                        ImageUrl="~//App_Themes/MBen/Grid/Collapse.gif" ToolTip="CollapseAll" />
                                </HeaderTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="FullName" UniqueName="FullName" HeaderText="Participant Name"
                                CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true"
                                FilterControlWidth="125px" FilterControlToolTip="Input name or part of name to search">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="EmployeeCode" UniqueName="EmployeeCode" HeaderText="Participant Code"
                                CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true"
                                FilterControlWidth="75px" FilterControlToolTip="Input a code to search" />
                        </Columns>
                        <DetailTables>
                            <telerik:GridTableView DataKeyNames="BeneficiaryID" DataSourceID="_dataSrcParticipantBeneficiaries"
                                Width="100%" runat="server" AllowFilteringByColumn="false" ShowFooter="true"
                                HorizontalAlign="Right">
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="ParticipantID" MasterKeyField="ParticipantID" />
                                </ParentTableRelation>
                                <Columns>
                                    <telerik:GridBoundColumn DataField="BeneficiaryID" UniqueName="BeneficiaryID" Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="Beneficiary" UniqueName="Beneficiary" HeaderText="Beneficiary Name"
                                        AllowFiltering="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="BeneficiaryType" UniqueName="BeneficiaryType"
                                        HeaderText="Beneficiary Type" HeaderStyle-Width="15%">                                       
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="BeneficiaryRelationship" UniqueName="BeneficiaryRelationship"
                                        HeaderText="Relationship" AllowFiltering="false" HeaderStyle-Width="15%">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="BeneficiaryPercent" UniqueName="BeneficiaryPercent"
                                        HeaderText="Beneficiary Percent" AllowFiltering="false" HeaderStyle-Width="18%">
                                    </telerik:GridBoundColumn>
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
                    </MasterTableView>                   
                </telerik:RadGrid>

code behind event handlers:

protected void rgBeneficiary_PreRender(object source, EventArgs e)
        {
            if (rgBeneficiary.MasterTableView.Items.Count == 0)
            {
                rgBeneficiary.ShowFooter = false;
            }
             
            RadAjaxManager.GetCurrent(Page).ClientEvents.OnRequestStart = "RequestStart";
        }       
 
        protected void rgBeneficiary_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName.Contains("Export"))
            {
                if (e.CommandName == "ExportToCsv")
                    rgBeneficiary.ExportSettings.ExportOnlyData = false;
 
               rgBeneficiary.MasterTableView.HierarchyDefaultExpanded = true;
            }
 
            #region Expand/Collapse All
 
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                (e.Item.FindControl("btnExpand") as ImageButton).Visible = !(e.Item.FindControl("btnExpand") as ImageButton).Visible;
                (e.Item.FindControl("btnCollapse") as ImageButton).Visible = !(e.Item.FindControl("btnCollapse") as ImageButton).Visible;
            }
            if (e.CommandName == "ExpandAll")
            {
                //Looping through each DataItem and making the "btnExpand" image button in the item visibility  to false and  "btnCollapse" visibility to true
                foreach (GridDataItem GridDataItem in rgBeneficiary.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem }))
                {
                    ImageButton btnExpand = (ImageButton)GridDataItem.FindControl("btnExpand");
                    btnExpand.Visible = false;
                    ImageButton btnCollapse = (ImageButton)GridDataItem.FindControl("btnCollapse");
                    btnCollapse.Visible = true;
                }
                //Exapanding the DataItem
                foreach (GridDataItem item in rgBeneficiary.Items)
                {
                    item.Expanded = true;
                }
                //Hiding the CollapseAll image in the header to true and ExpandAll image in the header to false
                GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
                ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll");
                imgCollapseAll.Visible = true;
                ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll");
                imgExpandAll.Visible = false;
            }
            if (e.CommandName == "CollapseAll")
            {
                //Looping through each DataItem and making the "btnExpand" image button in the item visibility  to true and  "btnCollapse" visibility to false
                foreach (GridDataItem GridDataItem in rgBeneficiary.MasterTableView.GetItems(new GridItemType[] { GridItemType.Item, GridItemType.AlternatingItem }))
                {
                    ImageButton btnExpand = (ImageButton)GridDataItem.FindControl("btnExpand");
                    btnExpand.Visible = true;
                    ImageButton btnCollapse = (ImageButton)GridDataItem.FindControl("btnCollapse");
                    btnCollapse.Visible = false;
                }
                //Collapsing the DataItem
                foreach (GridDataItem item in rgBeneficiary.Items)
                {
                    item.Expanded = false;
                }
                //Hiding the CollapseAll image in the header to false and ExpandAll image in the header to true
                GridHeaderItem GridHeaderItem = e.Item as GridHeaderItem;
                ImageButton imgCollapseAll = (ImageButton)GridHeaderItem.FindControl("CollapseAll");
                imgCollapseAll.Visible = false;
                ImageButton imgExpandAll = (ImageButton)GridHeaderItem.FindControl("ExpandAll");
                imgExpandAll.Visible = true;
            }
            #endregion
        }
 
        protected void rgBeneficiary_ItemCreated(object source, GridItemEventArgs e)
        {
            //removes unwanted line from commanditemdisplay
            if (e.Item is GridCommandItem)
            {
                ((Table)e.Item.Cells[0].Controls[0]).Rows[0].Cells[1].Controls.RemoveAt(1);
            }
        }

Any help is appreciated.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 09 Jan 2012, 07:03 AM
Hello,

Check the following demo which implements the same.
Grid / Export Hierarchical Grid

-Shinu.
Tags
Grid
Asked by
MBEN
Top achievements
Rank 1
Veteran
Answers by
Shinu
Top achievements
Rank 1
Share this question
or