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

Expand column exported to PDF

11 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ernest Mombay
Top achievements
Rank 1
Ernest Mombay asked on 20 Jul 2009, 05:03 PM
I have setup a NestedViewTemplate in my RadGrid. The template contains an ASP.NET DetailsView control that is populated upon expanding a row. I also have set up exporting to Excel and PDF through two external buttons. Here are my exporting settings:

<ExportSettings FileName="PDFExport" IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true"
        <Excel Format="ExcelML" /> 
        <Pdf PageTitle="Lookup Results" Subject="Lookup Results" /> 
</ExportSettings> 

Exporting through Excel works perfectly. However, when I export to PDF, the first column always shows. I have it setup so that upon exporting to PDF, to fix certain columns to the right width, and if the column's unique name is "ExpandColumn" or "RowIndicator", set width to 0 pixels, and make it invisible and not displayable.

Is there anything else I need to do to make the first expand column not display?

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jul 2009, 05:22 AM
Hi Ernest,

Give a try with the following code snippet to hide the ExpandColumn in the Exported PDF document.

CS:
 
protected void Button2_Click(object sender, EventArgs e) 
    { 
        
        RadGrid2.ExportSettings.ExportOnlyData = true
        RadGrid2.ExportSettings.OpenInNewWindow = true
 
 
        (RadGrid2.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem)["ExpandColumn"].Visible = false
 
        foreach (GridDataItem dataItem in RadGrid2.MasterTableView.Items) 
        { 
            dataItem["ExpandColumn"].Style["display"] = "none"
            dataItem["ExpandColumn"].Visible = false
        } 
 
        RadGrid2.MasterTableView.ExportToPdf(); 
    } 
 


Thanks
Shinu.
0
Ernest Mombay
Top achievements
Rank 1
answered on 21 Jul 2009, 12:57 PM
Thanks Shinu.

Your proposed solution did not work however. I have paging enabled, and when I stepped through to your proposed loop, only the items initially shown through the first page are counted. Even when I set a higher page size, it still would not remove the first column. Below is my modified export code:
protected void _btnExportPdf_Click(object sender, EventArgs e)  
        {  
            _gridLookup.ExportSettings.Pdf.PaperSize = GridPaperSize.Letter;  
            _gridLookup.ExportSettings.Pdf.PageHeight = Unit.Parse("8.5in");  
            _gridLookup.ExportSettings.Pdf.PageWidth = Unit.Parse("11in");  
 
            (_gridLookup.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem)["ExpandColumn"].Visible =  
                false;  
              
            foreach (GridColumn column in _gridLookup.MasterTableView.RenderColumns)  
            {  
                if (column.UniqueName == "Column4" || column.UniqueName == "Column5")  
                    column.HeaderStyle.Width = Unit.Pixel(120);  
                else if (column.UniqueName == "ExpandColumn" || column.UniqueName == "RowIndicator")  
                {  
                    column.Display = false;  
                    column.Visible = false;  
                    column.HeaderStyle.Width = Unit.Pixel(0);  
                }  
                else 
                    column.HeaderStyle.Width = Unit.Pixel(100);  
            }  
 
            foreach (GridDataItem dataItem in _gridLookup.MasterTableView.Items)  
            {  
                dataItem["ExpandColumn"].Text = "";  
                dataItem["ExpandColumn"].Style["display"] = "none";  
                dataItem["ExpandColumn"].Visible = false;  
            }  
 
            _gridLookup.MasterTableView.ExportToPdf();  
        } 
Also, I get the datasource through the NeedDataSource event, as I call a web service in there to get our customized data.
0
Ernest Mombay
Top achievements
Rank 1
answered on 22 Jul 2009, 01:51 PM
I just realized something... When I do the export on IE, the expand column is exported. However, if I export on Firefox, the column is not displayed and everything is fine. I still use the export code above. I wonder why that is...
0
Pavlina
Telerik team
answered on 23 Jul 2009, 08:21 AM
Hi Ernest,

I followed your scenario in order to replicate the issue you are facing but to no avail. Please find attached a simple runnable application that demonstrates the desired functionality. Give it a try and see if it works for you.

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ernest Mombay
Top achievements
Rank 1
answered on 23 Jul 2009, 07:39 PM
Thank you Pavlina.

Your sample is very close to mine. I'll attach my markup. Mind you this comes from a User control. Also, keep in mind that it works perfectly fine with Firefox. How is this dependent on browser?

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableHistory="True" 
    DefaultLoadingPanelID="RadAjaxLoadingPanel1">  
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="_gridLookup">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="_gridLookup" LoadingPanelID="RadAjaxLoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManager> 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Office2007" /> 
<telerik:RadGrid AutoGenerateColumns="False" ID="_gridLookup" AllowPaging="True" 
    AllowCustomPaging="True" AllowSorting="True" runat="server" Width="100%" GridLines="None" 
    Skin="Office2007" OnNeedDataSource="_gridLookup_NeedDataSource" 
    OnItemDataBound="_gridLookup_ItemDataBound" OnExcelExportCellFormatting="_gridLookup_ExcelExportCellFormatting" 
    OnExcelMLExportRowCreated="_gridLookup_ExcelMLExportRowCreated" OnExcelMLExportStylesCreated="_gridLookup_ExcelMLExportStylesCreated" 
    OnItemCreated="_gridLookup_ItemCreated" OnItemCommand="_gridLookup_ItemCommand" 
    OnPreRender="_gridLookup_PreRender">  
    <PagerStyle Mode="NextPrevAndNumeric" /> 
    <GroupingSettings CaseSensitive="false" /> 
    <MasterTableView EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true" UseAllDataFields="true" 
        AllowFilteringByColumn="True" DataKeyNames="PersonID" ClientDataKeyNames="PersonID" 
        GroupLoadMode="Server">  
        <Columns> 
            <telerik:GridBoundColumn HeaderText="First name" DataField="FirstName" UniqueName="FirstName" 
                SortExpression="FirstName" HeaderStyle-Width="60px" FilterControlWidth="60px" 
                AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="true">  
                <HeaderStyle Width="160px"></HeaderStyle> 
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="Last name" DataField="LastName" UniqueName="LastName" 
                SortExpression="LastName" HeaderStyle-Width="60px" FilterControlWidth="60px" 
                AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="true">  
                <HeaderStyle Width="160px"></HeaderStyle> 
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="Middle name" DataField="MiddleName" UniqueName="MiddleName" 
                SortExpression="MiddleName" HeaderStyle-Width="50px" FilterControlWidth="50px" 
                AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="true">  
                <HeaderStyle Width="115px"></HeaderStyle> 
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="DOB" DataField="DateOfBirth" UniqueName="DateOfBirth" 
                AllowFiltering="False">  
                <HeaderStyle Width="80px"></HeaderStyle> 
            </telerik:GridBoundColumn> 
        </Columns> 
        <NestedViewSettings> 
            <ParentTableRelation> 
                <telerik:GridRelationFields DetailKeyField="PersonID" MasterKeyField="PersonID" /> 
            </ParentTableRelation> 
        </NestedViewSettings> 
        <NestedViewTemplate> 
            <asp:Panel ID="Panel1" runat="server" BackColor="#eaeaea" CssClass="DetailsPanelTemplate">                  
                <asp:Label runat="server" ID="_lblPersonID" Visible="false" Text='<%# Bind("PersonID") %>'></asp:Label> 
                <asp:DetailsView ID="_dtlsMember" runat="server" Width="210px" GridLines="None" AutoGenerateRows="false" 
                    BackColor="White" HeaderText="Quick Member Details">  
                    <FieldHeaderStyle Font-Bold="true" /> 
                    <HeaderStyle BackColor="#ffbd69" Font-Bold="true" /> 
                    <Fields> 
                        <asp:BoundField HeaderText="Detail1:" DataField="Detail1" /> 
                        <asp:BoundField HeaderText="Detail2:" DataField="Detail2" /> 
                    </Fields> 
                </asp:DetailsView> 
                <href="Page.aspx?PersonID=<%# Eval("PersonID") %>">Click here for more details.</a> 
            </asp:Panel> 
        </NestedViewTemplate> 
        <AlternatingItemStyle BackColor="#CEDFEF" Font-Bold="False" Font-Italic="False" Font-Overline="False" 
            Font-Strikeout="False" Font-Underline="False" Wrap="True" /> 
        <PagerStyle Position="Bottom" AlwaysVisible="true" /> 
    </MasterTableView> 
    <ClientSettings EnablePostBackOnRowClick="true">  
        <Selecting AllowRowSelect="true" /> 
    </ClientSettings> 
    <ExportSettings FileName="GridResults" IgnorePaging="true" OpenInNewWindow="true" 
        ExportOnlyData="true">  
        <Excel Format="ExcelML" /> 
        <Pdf PageTitle="Grid Results" Subject="Grid Results" /> 
    </ExportSettings> 
</telerik:RadGrid> 
0
Pavlina
Telerik team
answered on 24 Jul 2009, 02:30 PM
Hi Ernest,

I followed your scenario in order to replicate the issue but to no avail.
At this point in order to find quick solution/fix of this problem I suggest you to modify my project in order to replicate the problem or create your own, fully runnable reproduction project.This will help us locate the exact problem in your particular layout and I will modify it for you in order to meet your requirements.

Regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ernest Mombay
Top achievements
Rank 1
answered on 27 Jul 2009, 01:28 PM

Thanks Pavlina.

 

I have edited the ASPX page from the project you sent to be like mine, and I was able to replicate the issue. I changed the grid to replicate how my grid is set up. Keep in mind the details view is not functioning, but the fact is the empty column is still being exported. Here is the updated grid: (I can't send in the project, don't know how)

<telerik:RadGrid ID="RadGrid1" DataSourceID="AccessDataSource1" runat="server" Skin="WebBlue" 
            Width="95%" AutoGenerateColumns="False" PageSize="5" AllowSorting="True" AllowPaging="True" 
            GridLines="None">  
            <PagerStyle Mode="Advanced"></PagerStyle> 
            <MasterTableView DataSourceID="AccessDataSource1" DataKeyNames="CustomerID" Width="100%" 
                HierarchyLoadMode="ServerOnDemand">  
                <Columns> 
                    <telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="CustomerID" HeaderButtonType="TextButton" 
                        DataField="CustomerID" UniqueName="CustomerID">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Contact Name" HeaderButtonType="TextButton" 
                        DataField="ContactName" UniqueName="ContactName">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Company" HeaderButtonType="TextButton" 
                        DataField="CompanyName" UniqueName="CompanyName">  
                    </telerik:GridBoundColumn> 
                </Columns> 
                <NestedViewSettings> 
                    <ParentTableRelation> 
                        <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" /> 
                    </ParentTableRelation> 
                </NestedViewSettings> 
                <NestedViewTemplate> 
                    <asp:Panel ID="Panel1" runat="server" BackColor="#eaeaea" CssClass="DetailsPanelTemplate">                          
                        <asp:Label runat="server" ID="_lblPersonID" Visible="false" Text='<%# Bind("CustomerID") %>'></asp:Label> 
                        <asp:DetailsView ID="_dtlsMember" runat="server" Width="210px" GridLines="None" AutoGenerateRows="false" 
                            BackColor="White" HeaderText="Quick Member Details" DataSourceID="AccessDataSource2" DataKeyNames="OrderID">  
                            <FieldHeaderStyle Font-Bold="true" /> 
                            <HeaderStyle BackColor="#ffbd69" Font-Bold="true" /> 
                            <Fields> 
                                <asp:BoundField HeaderText="Order ID:" DataField="OrderID" /> 
                                <asp:BoundField HeaderText="Order Date:" DataField="OrderDate" /> 
                                <asp:BoundField HeaderText="Employee ID:" DataField="EmployeeID" /> 
                            </Fields> 
                        </asp:DetailsView>                          
                    </asp:Panel> 
                </NestedViewTemplate> 
            </MasterTableView> 
            <ExportSettings FileName="EmployeeLookup" IgnorePaging="true" OpenInNewWindow="true" 
                ExportOnlyData="true">  
                <Excel Format="ExcelML" /> 
                <Pdf PageTitle="Employee Lookup Results" Subject="Employee Lookup Results" /> 
            </ExportSettings> 
        </telerik:RadGrid> 
0
Pavlina
Telerik team
answered on 27 Jul 2009, 04:39 PM
Hello Ernest,

I went through your code and find that IgnorePaging property set to true have caused the unexpected behavior when export on IE. You should hide the ExpandColumn on Pre_Render event and export to pdf will work properly.
Attached to this message is a simple runnable application which handles the desired functionality. Please give it a try and let me know if you need further assistance.

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ernest Mombay
Top achievements
Rank 1
answered on 27 Jul 2009, 06:10 PM
Thanks Pavlina.

I tried emulating your solution into my project but it seems to not work. When I look at your attached projected, you've added a pre-render event. However, this event is not attached to you grid, and thus is never fired (I can't step through it). When I plugged it into my pre-render event, I kept getting errors when getting the GridHeaderItem event for some reason.
(GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] 
So I'm a bit lost here.
0
Ernest Mombay
Top achievements
Rank 1
answered on 27 Jul 2009, 07:30 PM
I think I've solved my issue. I thank Pavlina for pointing out that the formatting must occur in the Pre_Render event of the grid. Here is my Pre_Render code below:
protected void _gridLookup_PreRender(object sender, EventArgs e)  
        {
            #region Backwards compatibility  
            HttpBrowserCapabilities findBrowser = Request.Browser;  
            string browserName = findBrowser.Browser;  
            double browserverson = browserName == "IE" ? Convert.ToDouble(findBrowser.Version) : 0.0;  
            if (browserName != "IE" || (browserName == "IE" && browserverson > 5.999))  
            {  
                foreach (GridColumn col in _gridLookup.MasterTableView.RenderColumns)  
                {  
                    if (col.UniqueName == "ExpandColumn")  
                    {  
                        col.Display = false;  
                        col.Visible = false;  
                    }  
                }  
            } 
            #endregion  
 
            if (_isPdfExporting && browserName == "IE")  
            {  
                GridHeaderItem header = _gridLookup.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;  
                header["ExpandColumn"].Style["display"] = "None";  
                header["ExpandColumn"].Visible = false;  
                header["RowIndicator"].Style["display"] = "None";  
                header["RowIndicator"].Visible = false;  
 
                foreach (GridDataItem dataItem in _gridLookup.MasterTableView.Items)  
                {  
                    dataItem["ExpandColumn"].Style["display"] = "None";  
                    dataItem["ExpandColumn"].Visible = false;  
                    dataItem["RowIndicator"].Style["display"] = "None";  
                    dataItem["RowIndicator"].Visible = false;  
                }  
                _isPdfExporting = false;  
            } 
I check for the browser type for browser compatibility issues. Any IE below 6 kills the Javascript that calls a postback on row click. So the collapse button needs to show. Also, for some reason, the export works fine in Firefox, and if I force visibility to false on those columns, the other columns are squished to the left. So the formatting will only occur in IE.
Is there any reason why this is so? Can there be a fix for that in the future?

Thanks, Ernest
0
Pavlina
Telerik team
answered on 30 Jul 2009, 01:47 PM
Hello Ernest,

Thank you for your feedback - I will forward your request to our developers for further consideration.

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Ernest Mombay
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ernest Mombay
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or