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

Set Font-Size of Column Headings

5 Answers 468 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 17 Aug 2011, 03:58 PM
** Disclaimer **
The Telerik product was just purchased by us less than 2 weeks ago and therefore as a Newbie, I may have posted this to the wrong forum, and I may be overlooking an obvious resolution.

** Problem **
Unable to set the font-size of the column headings when exporting a grid to PDF.

** Things Tried **
I have tried many things, including some samples directly from Telerik demos. For example:

    bool isPdfExport = false;

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) {
        if (isPdfExport && e.Item is GridDataItem) {
            /// <ColumnHeadings>
            if (e.Item is GridHeaderItem) {
                GridHeaderItem headerItem = (GridHeaderItem)e.Item;

                headerItem.Style["font-size"] = "6pt";

                foreach (TableCell cell in headerItem.Cells) {
                    cell.Style["font-size"] = "6pt";
                }
            }
            /// </ColumnHeadings>

            /// <ColumnData>
            if (e.Item is GridItem) {
                GridItem gridItem = (GridItem)e.Item;

                gridItem.Style["font-size"] = "6pt";

                foreach (TableCell cell in gridItem.Cells) {
                    cell.Style["font-size"] = "6pt";
                }
            /// </ColumnData>
            }
        } //End if (isPdfExport && e.Item is GridDataItem)
    } //End protected void RadGrid1_ItemCreated()

    protected void btnExport_Click(object sender, EventArgs e) {
        isPdfExport = true;

        this.RadGrid1.Visible = true;
        this.RadGrid1.MasterTableView.ExportToPdf();
    }

Within the above event, the ColumnHeadings section fails to resize the font. However, the ColumnData section *will* successfully resize the font. If I change the ColumnData section from 6pt to 12pt font, the data that appears under the column headings (after exporting to PDF) will be resized according. Change it back to 6pt and re-export, and the data is formatted properly.

When making the same change from 6pt to 12pt (or whatever) in the ColumnHeading section, there is no impact on the headings that appear in the PDF. The font size of the column headings remain unchanged. I have no success using "x-small" or "x-large" either (instead of a point size).

I have tried using similiar code in RadGrid1_ColumnCreated() as well as other grid events, but with no luck. BTW, here is the grid schema if interested:

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true"
                     GridLines="Both" BorderWidth="0.5" Visible="false" 
                     OnNeedDataSource="RadGrid1_NeedDataSource"
                     OnItemCreated="RadGrid1_ItemCreated"
                     OnDataBound="RadGrid1_DataBound"
                     OnColumnCreated="RadGrid1_ColumnCreated">
        <ClientSettings>
            <Resizing AllowColumnResize="true" />
        </ClientSettings>
        <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
            <Pdf AllowPrinting="true" PaperSize="Legal" PageHeight="8.5in" PageWidth="14in"
                 PageBottomMargin="10mm" PageTopMargin="20mm" PageLeftMargin="8mm" PageRightMargin="8mm" />
        </ExportSettings>
    </telerik:RadGrid>

** Resolution **
Unable to determine. Can someone please provide the proper way to resize Column Headings when exporting a grid to PDF?

Thank you,
Steven

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Aug 2011, 06:47 AM
Hello Steven,

Try the following code snippet to change the Font-size of Column Headings while exporting.
C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
 {
   if (e.CommandName == RadGrid.ExportToPdfCommandName)
     {
       GridHeaderItem HeaderItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
       HeaderItem["EmployeeID"].Style["font-size"] = "20pt";
     }
 }

Thanks,
Shinu.
0
Brian
Top achievements
Rank 1
answered on 18 Aug 2011, 08:03 PM
Shinu,

Thanks for your reply.

Is there anything extra that I have to do within my project to get the ItemCommand() to fire?

I have added OnItemCommand="RadGrid1_ItemCommand" to my <telerik:RadGrid ID="RadGrid1" and then added the protected void RadGrid1_ItemCommand() event to my web page, but nothing happens when I browse the page and export the grid to PDF? The size of the column headings do not change.

I don't think the event ItemCommand() is firing. If I place a breakpoint on the if command-line within ItemCommand(), the breakpoint is never triggered, which indicates to me that ItemCommand() is not being called or fired. Do I have to do anything special to cause this event to fire?

BTW, in case you didn't notice earlier, I am not using the <CommandItemTemplate> with my Telerik:RadGrid. I am using a separte asp:Button to trigger the ExportToPdf() method (illustrated above when I first posted this issue). I don't know if that has anything to do with the ItemCommand() not firing, but I thought I would let you know.

Thanks,
Steven
0
Shinu
Top achievements
Rank 2
answered on 19 Aug 2011, 06:59 AM
Hello Steven,

Since you are exporting to Pdf in a ButtonclickEvent try setting CommandName for the Button
aspx:
<asp:Button ID="Button1" runat="server" Text="Export" CommandName="Export" OnClick="btnExport_Click" />

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
 {
   if (e.CommandName =="Export")
     {
      //code here
     }
 }

Thanks,
Shinu.
0
Brian
Top achievements
Rank 1
answered on 19 Aug 2011, 02:25 PM
Shinu,

Thank you again for your reply.

I have applied your additional suggestion, but still no joy. The ItemCommand() is not firing. I have also tried adding RadGrid1.Rebind() to my button click event to ensure that this is not a binding issue. I have added EnableViewState="true" to the RadGrid1 schema and I tried adding EnablePostBackOnRowClick="true" to the <ClientSettings> within the RadGrid1 schema. The ItemCommand() event will not fire.

The more I think about this the more I find myself wondering what is an "Item" within the ItemCommand or within a RadGrid? Is an Item the grid itself or is it each row that makes up a grid, including the column heading row? Or is an "Item" a data row within the grid (not including the column heading row)? Is an Item each individual cell that makes up a grid? IOWs, what are the members of an Item or Items collection?

I kept wondering why the ItemCreated() event (that I posted above when I first opened this issue) is able to properly format the data rows that appear in the PDF file, but it will not format the column headings. I am thinking that the column headings may have already been processed (exported) by the time the ItemCreated() event fires, especially if column headings are not a member of the Item collection. This may explain why the GridHeaderItem headerItem code within my ItemCreated() event has no impact on the column heading format.

But the RadGrid also has an OnColumnCreated event and I tried to format the column headings within that event, but didn't see any formatting changes there either.

I keep thinking that I am overlooking something obvious and I'm just too new to the Telerik product to know what it is.
0
Brian
Top achievements
Rank 1
answered on 19 Aug 2011, 11:27 PM
Shinu,

This afternoon, a colleague and I found a resolution to this problem thru this other posting on the Telerik forum. After we applied the info from this other posting, we were also required to add one additional modification not listed in the posting. The modification that we added was in the button click event. Prior to the ApplyStylesToPDFExport call within the click event, we had to add a RadGrid1.Rebind() command-line. Once this command-line (along with the rest of the info in the other posting) was added to our web page, we could successfully format column headings when exporting our grid contents to a PDF file.

Optionally, we also removed the // Apply some css style to the data items // code from the ApplyStylesToPDFExport() method as well, b/c we simply did not need that code. But removal of this code was not necessary for our web page to work. It was simply our choice to remove what we did not need.

So Shinu, this issue is officially resolved and closed.

Thank you for your assistance,
Steven
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brian
Top achievements
Rank 1
Share this question
or