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

Exporting Hierarchical Data

3 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt Place
Top achievements
Rank 1
Matt Place asked on 09 Jun 2010, 07:33 PM
I'm running ASP.NET AJAX Q3 2009 and have a grid with a detail table that I need to export.
The master table is populated through the NeedDataSource event and the detail table is populated through the DetailTableDataBind event.

When exporting, I am unable to include the records from the detail table. here is the code for the grid on the aspx page

<telerik:RadGrid  
            ID="rdgCorrespondence"  
            runat="server"  
            AllowFilteringByColumn="True" 
            AllowPaging="True"  
            AllowSorting="True"  
            AutoGenerateColumns="False"  
            GridLines="None" 
            OnNeedDataSource="rdgCorrespondence_NeedDataSource"  
            OnDetailTableDataBind="rdgCorrespondence_DetailTableDataBind" 
            OnItemDataBound="rdgCorrespondence_ItemDataBound"  
            OnInsertCommand="rdgCorrespondence_InsertCommand" 
            OnUpdateCommand="rdgCorrespondence_UpdateCommand"  
            onitemcommand="rdgCorrespondence_ItemCommand"
            <MasterTableView  
                CommandItemDisplay="Top"  
                DataKeyNames="CorrespondenceID"  
                Name="Correspondences" 
                Width="100%" 
                HierarchyLoadMode="ServerBind"
                <CommandItemSettings  
                    ShowExportToExcelButton="true" 
                /> 
                 
                <EditFormSettings> 
                    <EditColumn UniqueName="EditCommandColumn1"
                    </EditColumn> 
                </EditFormSettings> 
                <HeaderStyle HorizontalAlign="Center" /> 
                <ExpandCollapseColumn Visible="True"
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridEditCommandColumn ButtonType="ImageButton"
                    </telerik:GridEditCommandColumn> 
                    <telerik:GridBoundColumn DataField="CorrespondenceID" HeaderText="ID" UniqueName="CorrespondenceID" 
                        ReadOnly="true" FilterControlWidth="20" ItemStyle-Width="25" ItemStyle-HorizontalAlign="Right" ForceExtractValue="Always"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="TypeName" HeaderText="Type" DataField="TypeName"
                    </telerik:GridBoundColumn> 
                </Columns> 
                <DetailTables> 
                    <telerik:GridTableView  
                        DataKeyNames="CorrespondenceNoteID"  
                        CommandItemDisplay="Top" 
                        Name="CorrespondenceNotes"  
                        Width="100%"  
                        AllowFilteringByColumn="false"  
                        BorderColor="#fff" 
                        HierarchyLoadMode="Client"
                        <ParentTableRelation> 
                            <telerik:GridRelationFields DetailKeyField="CorrespondenceID" MasterKeyField="CorrespondenceID" /> 
                        </ParentTableRelation> 
                        <Columns> 
                            <telerik:GridEditCommandColumn ButtonType="ImageButton"
                            </telerik:GridEditCommandColumn> 
                            <telerik:GridBoundColumn DataField="CorrespondenceNoteID" HeaderText="Note ID" UniqueName="CorrespondenceNoteID" 
                                ReadOnly="true"
                            </telerik:GridBoundColumn> 
                            <telerik:GridDateTimeColumn DataField="DateOfNote" HeaderText="Date" UniqueName="DateOfNote"
                            </telerik:GridDateTimeColumn> 
                            <telerik:GridBoundColumn DataField="Note" HeaderText="Comment" UniqueName="Note"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="CorrespondenceID" HeaderText="Correspondence ID" 
                                UniqueName="CorrespondenceID" ReadOnly="true" Display="false"
                            </telerik:GridBoundColumn> 
                        </Columns> 
                        <SortExpressions> 
                            <telerik:GridSortExpression FieldName="DateOfNote" SortOrder="Descending" /> 
                        </SortExpressions> 
                    </telerik:GridTableView> 
                </DetailTables> 
            </MasterTableView> 
        </telerik:RadGrid> 

and here is my excel call:
 
        protected void rdgCorrespondence_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            string fileName = "Correspondences"
 
            if (e.CommandName = RadGrid.ExportToExcelCommandName) 
            { 
                grid.ExportSettings.FileName = fileName; 
                grid.ExportSettings.HideStructureColumns = true
                grid.ExportSettings.IgnorePaging = true
                grid.ExportSettings.OpenInNewWindow = true
                grid.ExportSettings.ExportOnlyData = true
                grid.MasterTableView.ExportToExcel(); 
            } 
        } 

Is the current implementation of the radgrid not support this type of export?

3 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 09 Jun 2010, 09:59 PM
Hello Matt,

Please try to set HierarchyDefaultExpanded="true" and let me know how it goes.
<MasterTableView HierarchyDefaultExpanded="true" ...>

Best regards,
Daniel
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.
0
Matt Place
Top achievements
Rank 1
answered on 10 Jun 2010, 12:15 AM
Thanks for your response.

That displayed all the child detail tables as expected, however I have run into a couple other issues
There is an extra column preceding my data when exporting to excel. How can I get rid of it.  I have added the following code to remove the expand columns, edit command columns, and row indicator columns
        protected void rdgCorrespondence_ItemCommand(object source, GridCommandEventArgs e)   
        {   
            string fileName = "Correspondences";   
   
            HideEditColumn(grid.MasterTableView);  
  
            foreach (GridColumn col in grid.Columns)  
            {  
                if (col is GridRowIndicatorColumn || col is GridExpandColumn)  
                    col.Visible = false;  
            }  
  
            if (e.CommandName = RadGrid.ExportToExcelCommandName)   
            {   
                grid.ExportSettings.FileName = fileName;   
                grid.ExportSettings.HideStructureColumns = true;   
                grid.ExportSettings.IgnorePaging = true;   
                grid.ExportSettings.OpenInNewWindow = true;   
                grid.ExportSettings.ExportOnlyData = true;   
                grid.MasterTableView.ExportToExcel();   
            }   
        }   
  
        protected void HideEditColumn(GridTableView gTableView)  
        {  
            foreach (GridColumn col in gTableView.Columns)  
            {  
                if (col is GridEditCommandColumn)  
                {  
                    col.Display = false;  
                    col.Visible = false;  
                }  
            }  
      
            if (gTableView.DetailTables.Count > 0)  
            {  
                foreach (GridTableView gtv in gTableView.DetailTables)  
                {  
                    HideEditColumn(gtv);  
                }  
            }  
        }  
 

The detail tables are left aligned with the parent data/records. Is there a way I can insert a column on the child tables, or perhaps just include the row indicator columns on the child tables

And lastly, the child tables are being displayed despite the fact that there is no data in them. Is there a built in function to not display the child tables when there is not data to display?
0
Daniel
Telerik team
answered on 16 Jun 2010, 11:55 AM
Hello Matt,

Please test the attached project and let me know whether the demonstrated approach is suitable for you.

Best regards,
Daniel
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
Matt Place
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Matt Place
Top achievements
Rank 1
Share this question
or