PDF export missing column headers

4 posts, 0 answers
  1. Marcus
    Marcus avatar
    2 posts
    Member since:
    May 2015

    Posted 01 May 2015 Link to this post

    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?

     

  2. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 06 May 2015 Link to this post

    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.

     
  3. Marcus
    Marcus avatar
    2 posts
    Member since:
    May 2015

    Posted 07 May 2015 in reply to Kostadin Link to this post

    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

     

  4. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 11 May 2015 Link to this post

    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.

     
Back to Top