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

Export NestedViewTemplate Grid

7 Answers 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mehmet
Top achievements
Rank 1
Mehmet asked on 25 Mar 2015, 03:00 AM
Hi there,

I have gone through almost all the posts in the forum, however, none of them has helped me :(

I have got a Grid which contains a nested view template object and that consists of a grid as follow:

<telerik:RadGrid AutoGenerateColumns="False" ID="RadGrid1" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" runat="server" OnItemCommand="RadGrid1_ItemCommand"  OnItemCreated="RadGrid1_ItemCreated" EnableLinqExpressions="true" HtmlEncode="true" OnNeedDataSource="RadGrid1_NeedDataSource" GroupByExpression="JobStatusID Group By JobStatusID"
                        ShowGroupPanel="True" CellSpacing="-1" GridLines="Both" Skin="Office2010Silver" EnableViewState="true" Width="100%">
                        <PagerStyle Mode="NextPrevAndNumeric" />
                        <GroupingSettings CaseSensitive="false" />
                        <ClientSettings AllowKeyboardNavigation="true">
                        </ClientSettings>
                        <ExportSettings OpenInNewWindow="true" FileName="i-Dispatch General Report">
                            <Pdf PageHeight="210mm" PageWidth="297mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin="45mm"
                                BorderStyle="Medium" BorderColor="#666666" PaperSize="A4">
                            </Pdf>
                        </ExportSettings>
                        <MasterTableView Width="100%" DataKeyNames="JobID" HierarchyLoadMode="ServerOnDemand">
                            <Columns>
                                <telerik:GridMaskedColumn DataField="JobID" HeaderText="JobID#"
                                    FilterControlWidth="50px" AutoPostBackOnFilter="false" CurrentFilterFunction="EqualTo"
                                    FilterDelay="2000" ShowFilterIcon="false" Mask="#####">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text=""></ModelErrorMessage>
                                    </ColumnValidationSettings>
                                </telerik:GridMaskedColumn>
                                <telerik:GridBoundColumn HeaderText="Customer Ref No" DataField="JobCustomerRefNo" UniqueName="JobCustomerRefNo"
                                    SortExpression="JobCustomerRefNo" HeaderStyle-Width="180px" FilterControlAltText="Filter JobCustomerRefNo column">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text=""></ModelErrorMessage>
                                    </ColumnValidationSettings>
 
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="JobTitle" FilterControlAltText="Filter JobTitle column" HeaderText="Job Title" SortExpression="JobTitle" UniqueName="JobTitle">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridDateTimeColumn DataField="JobBookedDate" PickerType="DatePicker" EnableTimeIndependentFiltering="true"
                                    DataFormatString="{0:dd/MM/yyyy HH:mm }" DataType="System.DateTime" FilterControlAltText="Filter JobBookedDate column" HeaderText="Job Booked Date" SortExpression="JobBookedDate" UniqueName="JobBookedDate">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridDateTimeColumn>
                                <telerik:GridBoundColumn DataField="JobAddress1" FilterControlAltText="Filter JobAddress1 column" HeaderText="Address" SortExpression="JobAddress1" UniqueName="JobAddress1">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="JobSuburb" FilterControlAltText="Filter JobSuburb column" HeaderText="Suburb" SortExpression="JobSuburb" UniqueName="JobSuburb">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="JobPostCode" FilterControlAltText="Filter JobPostCode column" HeaderText="PostCode" SortExpression="JobPostCode" UniqueName="JobPostCode">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="JobState" FilterControlAltText="Filter JobState column" HeaderText="State" SortExpression="JobState" UniqueName="JobState">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn DataField="JobStatusID" HeaderText="Status Type" UniqueName="JobStatusID"
                                    HeaderStyle-Width="200px" SortExpression="JobStatusID">
                                    <FilterTemplate>
                                        <telerik:RadComboBox ID="comboJobStatus" DataTextField="JobStatusName"
                                            DataValueField="JobStatusID" Height="100px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("JobStatusID").CurrentFilterValue %>'
                                            runat="server" OnClientSelectedIndexChanged="JobStatusIndexChanged">
                                            <Items>
                                                <telerik:RadComboBoxItem Text="All" />
                                            </Items>
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
                                            <script type="text/javascript">
                                                function JobStatusIndexChanged(sender, args) {
                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                    tableView.filter("JobStatusID", args.get_item().get_value(), "EqualTo");
                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
                                    <ItemTemplate>
                                        <%# Eval("JobStatus") %>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="ClientID" HeaderText="Client" UniqueName="ClientID"
                                    HeaderStyle-Width="200px" SortExpression="ClientID">
                                    <FilterTemplate>
                                        <telerik:RadComboBox ID="comboClient" DataTextField="ClientName"
                                            DataValueField="ClientID" Height="100px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ClientID").CurrentFilterValue %>'
                                            runat="server" OnClientSelectedIndexChanged="ClientIndexChanged">
                                            <Items>
                                                <telerik:RadComboBoxItem Text="All" />
                                            </Items>
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
                                            <script type="text/javascript">
                                                function ClientIndexChanged(sender, args) {
                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                    tableView.filter("ClientID", args.get_item().get_value(), "EqualTo");
                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
                                    <ItemTemplate>
                                        <%# Eval("Client") %>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="AssignedStaffID" HeaderText="Staff" UniqueName="AssignedStaffID"
                                    HeaderStyle-Width="200px" SortExpression="AssignedStaffID">
                                    <FilterTemplate>
                                        <telerik:RadComboBox ID="comboStaff" DataTextField="StaffName"
                                            DataValueField="StaffID" Height="100px" AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("AssignedStaffID").CurrentFilterValue %>'
                                            runat="server" OnClientSelectedIndexChanged="StaffIndexChanged">
                                            <Items>
                                                <telerik:RadComboBoxItem Text="All" />
                                            </Items>
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="RadScriptBlock10" runat="server">
                                            <script type="text/javascript">
                                                function StaffIndexChanged(sender, args) {
                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                    tableView.filter("AssignedStaffID", args.get_item().get_value(), "EqualTo");
                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
                                    <ItemTemplate>
                                        <%# Eval("AssignedStaff") %>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                            <NestedViewTemplate>
                                <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false">
                                    <telerik:RadGrid runat="server" ID="JobStatusGrid" OnNeedDataSource="JobStatusGrid_NeedDataSource">
                                        <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true"
                                            DataKeyNames="JobStatusHistoryID" PageSize="7" HierarchyLoadMode="Client">
                                            <Columns>
                                                <telerik:GridBoundColumn HeaderText="Status Type" HeaderButtonType="TextButton"
                                                    DataField="JobStatus" UniqueName="JobStatusID">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="Created By" HeaderButtonType="TextButton"
                                                    DataField="CreatedBy" UniqueName="CreatedBy">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn HeaderText="Created On" HeaderButtonType="TextButton"
                                                    DataField="CreatedOn" UniqueName="CreatedOn">
                                                </telerik:GridBoundColumn>
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>
                                </asp:Panel>
                            </NestedViewTemplate>
                        </MasterTableView>
                        <ClientSettings AllowDragToGroup="true">
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        </ClientSettings>
                    </telerik:RadGrid>

My approach is to export the grid into an excel or a pdf file with the following code:

protected void btnGeneralReportPDF_Click(object sender, ImageClickEventArgs e)
        {
            //RadGrid1.ExportSettings.ExportOnlyData = true;
            RadGrid1.ExportSettings.OpenInNewWindow = true;
            //RadGrid1.ExportSettings.IgnorePaging = true;
 
            
            headerMiddleCell = headerMiddleCell.Replace("<$companyname$>", "company name");
            headerMiddleCell = headerMiddleCell.Replace("<$reportname$>", "Report");
            headerMiddleCell = headerMiddleCell.Replace("<$daterange$>", "1-1-2015 / 2-2-2015");           
            RadGrid1.ExportSettings.Pdf.PageHeader.MiddleCell.Text = headerMiddleCell;
            // to get lanscape orientation
            RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse("162mm");
            RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse("600mm");
 
            foreach (GridDataItem gi in RadGrid1.MasterTableView.Items)
            {
                gi.Expanded = true;
                if (gi.HasChildItems)
                {
                    RadGrid rgHeader = (RadGrid)gi.ChildItem.NestedViewCell.Controls[0].Controls[1].Controls[1];
                    rgHeader.Rebind();                   
                }
            }
            RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
 
            //RadGrid1.Rebind();           
            RadGrid1.MasterTableView.ExportToPdf();
        }

The above code jumps into "JobStatusGrid_NeedDataSource" method in order to populate the nested data grid, however, it doesn't help me out to come up in the exported file.

Could you please advise me ?
Thank you

7 Answers, 1 is accepted

Sort by
0
Mehmet
Top achievements
Rank 1
answered on 25 Mar 2015, 10:53 PM
Can I have an answer please ?
Thank you
0
Kostadin
Telerik team
answered on 27 Mar 2015, 01:18 PM
Hello Mehmet,

I examine the provided code and it seems correct. Nevertheless I prepared a small runnable sample based on your logic and on my side the nested grid is exported. Could you please give it a try and let me know how it differs from your real setup?

Regards,
Kostadin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mehmet
Top achievements
Rank 1
answered on 30 Mar 2015, 12:45 AM
Did you get my sample worked on your end?
0
Kostadin
Telerik team
answered on 01 Apr 2015, 12:33 PM
Hello Mehmet,

I was unable to run the provided code snippet since most of the server side logic is missing. Nevertheless I tried to replicate the issue in the sample from my previous reply but to no avail. Could you please compare it with your project and if you are able to replicate the issue in my sample? This way I will be able to debug it locally and provide you with a proper solution.

Regards,
Kostadin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mehmet
Top achievements
Rank 1
answered on 02 Apr 2015, 03:33 AM
I've made a sample and I've created a ticket to be seen/solved asap .
thank you
0
Mehmet
Top achievements
Rank 1
answered on 02 Apr 2015, 03:37 AM
i've made a sample and attached with a ticket number.
hope to be solve asap
thank you
0
Kostadin
Telerik team
answered on 03 Apr 2015, 10:02 AM
Hi Mehmet,

I have already answered your support ticket and I will post the answer here as well if other users have a similar issue as yours.

"The reason for that behavior is that you initially hide the Panel which wraps the inner grid and even you change its visibility after a rebind the panel will be hid as well.
A possible solution is to remove the panel or not hide it initially. Another possible solution is to check whether the item is expanded on ItemCreated and if it does to show the panel. Additionally you need to set RetainExpandStateOnRebind property of the MasterTableView that will prevent collapsing the item after the export.
"

Regards,
Kostadin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Mehmet
Top achievements
Rank 1
Answers by
Mehmet
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or