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

Exporting NestedViewTemplate Grid with "ServerOnDemand"

3 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Furner
Top achievements
Rank 2
Brian Furner asked on 19 Nov 2009, 07:02 PM
I have a RadGrid on my page which contains a NestedViewTemplate.  Every level of the hierarchy has its LoadMode set to "ServerOnDemand".

                <telerik:RadGrid ID="rgMonthly" runat="server" GridLines="None" DataSourceID="odsAcctsByPI" 
                    OnColumnCreated="rgMonthly_ColumnCreated" OnItemDataBound="rgMonthly_ItemDataBound" 
                    OnPreRender="rgMonthly_PreRender" AutoGenerateColumns="true"
                    <MasterTableView DataSourceID="odsAcctsByPI" DataKeyNames="SlAcct6Num" HierarchyLoadMode="ServerOnDemand" 
                        EnableColumnsViewState="False"
                        <NestedViewSettings DataSourceID="odsGroupsByAcct"
                            <ParentTableRelation> 
                                <telerik:GridRelationFields DetailKeyField="SlAcct6Num" MasterKeyField="SlAcct6Num" /> 
                            </ParentTableRelation> 
                        </NestedViewSettings> 
                        <NestedViewTemplate> 
                            <telerik:RadGrid ID="rgSubs" runat="server" GridLines="None" DataSourceID="odsGroupsByAcct" 
                                AutoGenerateColumns="true" OnColumnCreated="rgSubs_ColumnCreated"  OnItemDataBound="rgSubs_ItemDataBound"
                                <MasterTableView DataSourceID="odsGroupsByAcct" DataKeyNames="SlAcct6Num,GroupID" 
                                    HierarchyLoadMode="ServerOnDemand" EnableColumnsViewState="False"
                                    <DetailTables> 
                                        <telerik:GridTableView Width="100%" runat="server" HierarchyLoadMode="ServerOnDemand" 
                                            AutoGenerateColumns="true" EnableColumnsViewState="False" DataKeyNames="SlAcct6Num,GroupID" 
                                            DataSourceID="odsSubAcctsByGroup"
                                            <ParentTableRelation> 
                                                <telerik:GridRelationFields DetailKeyField="GroupID" MasterKeyField="GroupID" /> 
                                                <telerik:GridRelationFields DetailKeyField="SlAcct6Num" MasterKeyField="SlAcct6Num" /> 
                                            </ParentTableRelation> 
                                        </telerik:GridTableView> 
                                    </DetailTables> 
                                </MasterTableView> 
                            </telerik:RadGrid> 
                        </NestedViewTemplate> 
                    </MasterTableView> 
                </telerik:RadGrid> 
 

When I attempt to export data to Excel, only the top-level data is being exported.  Here is the code I use to export.

protected void btnExcel_Click(object sender, EventArgs e) 
    rgMonthly.ExportSettings.OpenInNewWindow = true
    rgMonthly.ExportSettings.ExportOnlyData = true
    rgMonthly.ExportSettings.IgnorePaging = true
    foreach (GridDataItem gi in rgMonthly.MasterTableView.Items) 
    { 
        gi.Expanded = true
        if (gi.HasChildItems) 
        { 
            RadGrid rgSubs = (RadGrid)gi.ChildItem.NestedViewCell.Controls[0].Controls[1]; 
 
            foreach (GridDataItem gilvl3 in rgSubs.MasterTableView.Items) 
            { 
                if (!gilvl3.KeyValues.Contains("-1")) 
                { 
                    gilvl3.Expanded = true
                } 
            } 
        } 
    } 
    rgMonthly.MasterTableView.ExportToExcel(); 
 

If every level is set to "ServerBind", then I am able to get an export of all the data.  However, I would prefer to use "ServerOnDemand" as it is quicker to navigate prior to export.

Is there any way to get all the data to export using "ServerOnDemand"?

Thanks,

Brian Furner



3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 25 Nov 2009, 01:08 PM
Hello Brian,

In my opinion it doesn't matter whether your hierarchy expand mode setting is ServerBind or ServerOnDemand as long as you use IgnorePaging="true". IgnorePaging will cause RadGrid to rebind before export and therefore your expanded items will collapse.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Brian Furner
Top achievements
Rank 2
answered on 29 Jan 2010, 05:42 PM
Daniel --

I just revisited this issue and even with IgnorePaging = true, it is only exporting the top level of the hierarchy to excel.
Would you happen to have any additional suggestions?

Thanks,

Brian
0
Daniel
Telerik team
answered on 04 Feb 2010, 11:41 AM
Hello Brian,

You could use the HierarchyDefaultExpanded property in order to expand all items:
protected void btnExcel_Click(object sender, EventArgs e)
{
    rgMonthly.ExportSettings.OpenInNewWindow = true;
    rgMonthly.ExportSettings.ExportOnlyData = true;
    rgMonthly.ExportSettings.IgnorePaging = true;
    foreach (GridDataItem gi in rgMonthly.MasterTableView.Items)
    {
        gi.Expanded = true;
        if (gi.HasChildItems)
        {
            RadGrid rgSubs = (RadGrid)gi.ChildItem.NestedViewCell.Controls[0].Controls[1];
 
            foreach (GridDataItem gilvl3 in rgSubs.MasterTableView.Items)
            {
                if (!gilvl3.KeyValues.Contains("-1"))
                {
                    gilvl3.Expanded = true;
                }
            }
        }
    }
    rgMonthly.MasterTableView.HierarchyDefaultExpanded = true;
    rgMonthly.MasterTableView.ExportToExcel();
}

Let me know whether this helps.

Best regards,
Daniel
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Brian Furner
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Brian Furner
Top achievements
Rank 2
Share this question
or