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

Export styles not being applied in IE

4 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 30 Mar 2010, 07:22 PM
I'm having a problem with PDF exporting from RadGrid.
Basically the programmatic styles I apply to the columns and cells are not getting applied if I export using Internet Explorer. Firefox and Chrome work fine. I'm utterly at a loss as to how this happens, here is the style-specific code I use:

protected void btnExport_Click(object sender, EventArgs e) 
    { 
        isExport = true
        List_SelectedIndexChanged(new object(), new EventArgs()); //this applies a filter expression based on front end controls 
        ApplyColumnSettings(); 
        
        G1.ExportSettings.ExportOnlyData = true
        G1.ExportSettings.OpenInNewWindow = true
        G1.ExportSettings.FileName = "FileName"
        G1.ExportSettings.Pdf.Title = "Title"
        G1.ExportSettings.Pdf.Author = "Author"
        expanded = new bool[G1.Items.Count];             
        foreach (GridDataItem i in G1.Items) 
        { 
            if (i.Expanded) 
                expanded[i.ItemIndex] = true
            else 
                expanded[i.ItemIndex] = false
        } 
        G1.MasterTableView.ExportToPdf(); 
    } 
protected void ApplyColumnSettings() 
    { 
        foreach (GridColumn col in G1.MasterTableView.Columns) 
        {           
            switch (col.UniqueName) 
            { 
                case "exCol": col.Visible = falsebreak
                case "ExpandColumn": col.Visible = falsebreak
                case "ItemNumber": col.Visible = falsebreak
                case "ItemNumberLink": col.Visible = true; col.HeaderStyle.Width = Unit.Pixel(37);break
                case "COURSE_ID": col.HeaderStyle.Width = Unit.Pixel(130); break
                case "COURSE_TITLE": col.HeaderStyle.Width = Unit.Pixel(255); break
                case "INSTR_NAME": col.HeaderStyle.Width = Unit.Pixel(80); break
                case "day_CD": col.HeaderStyle.Width = Unit.Pixel(100); break
                case "time": col.HeaderStyle.Width = Unit.Pixel(120); break
                case "room_loc": col.HeaderStyle.Width = Unit.Pixel(130); break
                case "BRANCH": col.HeaderStyle.Width = Unit.Pixel(100); break
                case "type": col.HeaderStyle.Width = Unit.Pixel(70); break
                case "SeatsLeft": col.HeaderStyle.Width = Unit.Pixel(70); break
                case "cr": col.HeaderStyle.Width = Unit.Pixel(50); break
                 
            }                 
        } 
    } 
 
    protected void G1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (isExport)         
            ApplyPDFStyles(e.Item);         
    } 
 
protected void ApplyPDFStyles(GridItem item) 
    { 
        if (item is GridHeaderItem)                         
            item.Style["background-color"] = "#EEEEEE";         
        foreach (TableCell cell in item.Cells)         
            cell.Style["text-align"] = "left"
         
    } 
 


I've attached a picture showing how the header styles come out (the data fallows the same patterns), notice how the far right column gets chomped off all together...

Any ideas?

4 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 30 Mar 2010, 10:45 PM
I have done some more debugging and found what I believe to be a bug or at least an oversight with how the Export to PDF works.

I compared the raw HTML which I captured from the OnPdfExporting event.
I noticed that the HTML generated for Chrome was not the same as the html generated for IE, it was very close, but there was 1 subtle difference:

    <colgroup> 
        <col style="width:20px;display:none;" /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
        <col  /> 
</colgroup> 

In chrome, the first <col> tag has a display:none style, where as in IE, the <col> tag is simply not there (so there is 1 less ,<col> tag in the <colgroup>).

I tracked down what the first row is, it is the default Expand column built into the rad grid. In my code however I have this:

protected void G1_DataBound(object sender, EventArgs e) 
     G1.MasterTableView.GetColumn("ExpandColumn").Display = false

Because want the grid to be expand/collapsible, but i had the row expand/collapse functionality manually added in elsewhere.

So basically the situation is that setting the .Display property of a Grid column to false makes the column get deleted from the html rendering, which causes the last column to get cut off in the PDF rendering because it's expecting 1 less column...

I'd be appreciative of one anyones (especially Telerik developers) thoughts on this as well as any good work around...

Using 2010.1.309.35 (I've also tested with Q3 2009 and it's the same).


0
Daniel
Telerik team
answered on 02 Apr 2010, 03:15 PM
Hello Adam,

I answered in the support ticket you submitted. I suppose the problem is related to browser behavior. Either way, when we identify the exact issue I will post the solution here.

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Accepted
Daniel
Telerik team
answered on 05 Apr 2010, 01:34 PM
As I thought, the problem arises when one set visibility:hidden to a col element in Internet Explorer 7 (or IE8 compatibility mode) - this will hide the neighboring column.

In the scenario below, if you want to hide the column you can use one of the following options:

1) Use HideStructureColumns
<ExportSettings HideStructureColumns="true" />
<MasterTableView...

2) Set the column width to 1px
protected void  RadGrid1_DataBound(object sender, EventArgs e)
{
    RadGrid1.MasterTableView.GetColumn("ExpandColumn").HeaderStyle.Width = 1;
}

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Adam
Top achievements
Rank 1
answered on 05 Apr 2010, 06:09 PM
Setting the header column width to 1 worked well for my situation (HideStructureColumns does work as advertised also).
Thanks for the help!
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or