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

PDF export missing column headers

3 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 01 May 2015, 02:57 PM

I am using several pages with grids all with Word, CSV, Excel and PDF export
All export the column headers (i.e. field labels) except the PDF exportI
have tried a multitude of settings without result although I think this
used to work before we moved to using GridTemplateColumn

Currently these are the export settings in aspx

<ExportSettings ExportOnlyData="True" IgnorePaging="true" FileName="TimesheetList" OpenInNewWindow="true" HideStructureColumns="true"
    Pdf-DisableContentEncryption="true" Pdf-Title="Timesheet list" UseItemStyles="false" Word-Format="Html" Pdf-PaperSize="A4" Excel-Format="Html">
    <Pdf PageHeight="297mm" PageWidth="420mm" PageTopMargin="20mm"
        PageRightMargin="10mm" PageLeftMargin="10mm"
        BorderStyle="Thin" BorderColor="#666666" PaperSize="A4" ForceTextWrap="True">
    </Pdf>
</ExportSettings>

And here is the code behind

case "exportpdf":               

    isExport = true;
    RadGridTimesheets.MasterTableView.ExportToPdf();
 
    Response.AppendCookie(CustomNavigationHelper.CreateExportCookie());
    break;

Any ideas what I am doing wrong?

 

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 06 May 2015, 06:44 AM
Hi Marcus,

Note that not all controls in the HeaderTemplate will get exported automatically. Generally you need to access the control in the header temaplte and manually set it value to the header cell. For instance if you have a RadComboBox you can use the following approach to loop through all header cell and if the cell contains a RadComboBox control to set its value as a Text property of the TableCell.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem && isExport)
    {
        GridHeaderItem header = e.Item as GridHeaderItem;
 
        foreach (TableCell headerCell in header.Cells)
        {
            foreach (Control control in headerCell.Controls)
            {
                if (control is RadComboBox)
                {
                    headerCell.Text = (control as RadComboBox).SelectedItem.Text;
                }
            }
        }
    }
}

Keep in mind that you need to disable ExportOnlyData and IgnorePaging properties. In case you need to export all grid's data you can use disable AllowPaging property and rebind the grid.
bool isExport = false;
protected void Button1_Click(object sender, EventArgs e)
{
    isExport = true;
    RadGrid1.ExportSettings.ExportOnlyData = false;
    RadGrid1.ExportSettings.IgnorePaging = false;
    RadGrid1.AllowPaging = false;
    RadGrid1.Rebind();
    RadGrid1.MasterTableView.ExportToPdf();
}


Regards,
Kostadin
Telerik
 

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

 
0
Marcus
Top achievements
Rank 1
answered on 07 May 2015, 08:17 AM

Hi Kostadin

Thanks for that but not quite what I am looking for

The text is held on GridTemplateColumn not a radcombo box

<telerik:GridTemplateColumn DataField="AgencyName" HeaderText="Agency Name" SortExpression="CRM_Unitum.dbo.accounts.name" UniqueName="AgencyName" AutoPostBackOnFilter="true" AllowSorting="true" ShowSortIcon="false" CurrentFilterFunction="StartsWith">
    <HeaderTemplate>
        <telerik:RadComboBox ID="dlCustom_AgencyName" EmptyMessage="" Label="" runat="server" EnableScreenBoundaryDetection="true" MaxHeight="300px" Width="80px" DropDownWidth="280px"
         AutoPostBack="false" HighlightTemplatedItems="true" EnableLoadOnDemand="true"  OnItemsRequested="dlAgencyName_ItemsRequested"
         ClientIDMode="Static" OnClientSelectedIndexChanged='function(sender, args){ApplyClientFilter(sender, args, 1);}'>
        </telerik:RadComboBox>
    </HeaderTemplate>
    <ItemTemplate>

 

And if I use the settings behind you suggest I get no data - just a one page empty PDF

thanks

Marcus

 

0
Kostadin
Telerik team
answered on 11 May 2015, 12:42 PM
Hi Marcus,

I am afraid when using a HeaderTemplate the HeaderText that you have specified will be overridden and you have to manually set the Text property on TableCell as demonstrated in my previous reply.

Regards,
Kostadin
Telerik
 

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

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