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

RadGrid NestedViewTemplate ExportToPdf

3 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 24 Apr 2015, 10:01 AM

Hello

I have a radgrid with a NestedViewTemplate.  Inside this are 3 fieldsets with either lablels or LIs.  All are bound on the dataitembound event.  When I export to pdf, the labels & LIs (as text only) are present, but the fieldsets are not, so the horizontal organization of the data is lost... the labels export in a vertical stack.

I have tried replacing the fieldsets with spans to manage placement (I have seen a number of articles regarding div and width... so none of that).

 I also tried to various "manipulations" the grid_PreRender.  I note the fieldset is present as text of a LiteralControl and the actual Labels are Labels.  The LiteralControls have \r\n\ & up to 24 spaces (this matches the html layout in VS).  I have stripped all this out, tried creating new Panels and adding the Label controls to these, creating tables and adding the control text to the cells... and so on... but nothing seems to reformat this export.

here is my MasterTableView with NestedViewTemplate

  <telerik:RadGrid ID="gvServiceItems" runat="server" DataKeyNames="ID" OnNeedDataSource="gvServiceItems_NeedDataSource"
            OnItemCommand="gvServiceItems_OnItemCommand" OnItemDataBound="gvServiceItems_OnItemDataBound" OnPreRender="gvServiceItems_PreRender"
            ShowGroupPanel="true" EnableHierarchyExpandAll="true">
            <ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true">
            </ExportSettings>
            <ClientSettings AllowDragToGroup="true">
            </ClientSettings>
            <GroupingSettings ShowUnGroupButton="true"></GroupingSettings>

  <MasterTableView DataKeyNames="ID" Name="EstimateRequests">
                <NestedViewTemplate>
                    <span style="float: left; width: 30%; margin: 10px;">
                        <fieldset style="float: left; width: 96%; text-align: left; min-height: 124px;">
                            <legend>
                                <asp:Label ID="lblInfo" runat="server" Text="lblInfo" SkinID="LabelSeperatorTitle"></asp:Label>
                            </legend>
                            <p>
                                <asp:Label ID="lblDescription" runat="server" Text="lblDescription" SkinID="LabelRadSilk"></asp:Label><br />
                                <asp:Label ID="lblDescriptionData" runat="server" Text="lblDescriptionData" SkinID="LabelData"></asp:Label>
                            </p>
                            <p>
                                <asp:Label ID="lblRequestNotes" runat="server" Text="lblRequestNotes" SkinID="LabelRadSilk"></asp:Label><br />
                                <asp:Label ID="lblRequestNotesData" runat="server" Text="lblRequestNotesData" SkinID="LabelData"></asp:Label>
                            </p>
                        </fieldset>
                    </span>
                    <span style="float: left; width: 30%; margin: 10px;">
                        <fieldset style="float: left; width: 96%; text-align: left; min-height: 124px;">
                            <legend>
                                <asp:Label ID="lblEquipment" runat="server" Text="lblEquipment" SkinID="LabelSeperatorTitle"></asp:Label>
                            </legend>
                            <asp:Label ID="lblEquipmentData" runat="server" Text="lblEquipmentData"></asp:Label>
                        </fieldset>
                    </span>
                    <span style="float: left; width: 30%; margin: 10px;">
                        <fieldset style="float: left; width: 96%; text-align: left; min-height: 124px;">
                            <legend>
                                <asp:Label ID="lblParts" runat="server" Text="lblParts" SkinID="LabelSeperatorTitle"></asp:Label>
                            </legend>
                            <asp:Label ID="lblPartsData" runat="server" Text="lblPartsData"></asp:Label>
                        </fieldset>
                    </span>
                </NestedViewTemplate>
                <Columns>

                </Columns>

 

My grid_PreRender

 

  protected void gvServiceItems_PreRender(object sender, EventArgs e)
        {
            if (IsExport)
            {
                foreach (GridHeaderItem header in gvServiceItems.MasterTableView.GetItems(GridItemType.Header))
                {
                    foreach (TableCell cell in header.Cells)
                    {
                        cell.Style["font-family"] = "Arial Unicode MS";
                        cell.Style["font-size"] = "11px";
                        cell.Style["color"] = "black";
                        cell.Style["font-weight"] = "bold";
                        cell.Style["padding"] = "10px 0 4px 0";
                        cell.Style["margin"] = "0 4px";
                        cell.Style["text-align"] = "left";
                        cell.Style["background-color"] = "#ebf0f6";
                    }
                }

                int rowNumber = 0;

                foreach (GridDataItem item in gvServiceItems.MasterTableView.Items)
                {
                    foreach (TableCell cell in item.Cells)
                    {
                        cell.Style["font-family"] = "Arial Unicode MS";
                        cell.Style["font-size"] = "9px";
                        cell.Style["color"] = "black";
                        if (rowNumber.IsEven())
                            cell.Style["background-color"] = "#fff";
                        else
                            cell.Style["background-color"] = "#f3f6f9";

                    }
                    rowNumber++;

                    item.Expanded = true;

 

if (item.HasChildItems)

 

 

Any direction would be appreciated.

 

3 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 28 Apr 2015, 09:19 AM

I am still stuck on this... anyone have a thought ???

 

Thanks

0
Accepted
Kostadin
Telerik team
answered on 29 Apr 2015, 08:14 AM
Hello Daniel,

Keep in mind that not all html element could be parsed in the PDF document and fieldset is one of them. A possible solution is to either add a div element or a table element. If you are using a table element there is a few mandatory steps that you have to follow. Please check out Exporting HTML table section in the following help article.

Regards,
Kostadin
Telerik
 

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

 
0
Daniel
Top achievements
Rank 1
answered on 29 Apr 2015, 03:15 PM

Hi Kostadin

I did manage to format this in my export.  

A couple notes for anyone coming along

  •  I removed fieldset (as Kostadin explains it does not export)
  • I structured the layout of the page using tables
  • Used all inline styles, no css classes
  • in the Grid_PreRender...
    • Locate your Controls LiteralControls or Literals in the Item.ChildItems (I hard coded to the controls for now... may write a method to interate thought later) - there I did a .Replace on the text that contained my style formatting to adjust moving sizes, fonts, etc to compensate moving from a web format to a printed fomat.
    • Here is a sample
    •  ((LiteralControl)item.ChildItem.Controls[1].Controls[0].Controls[1].Controls[0]).Text =
                                  ((LiteralControl)item.ChildItem.Controls[1].Controls[0].Controls[1].Controls[0]).Text
                                          .Replace("width:350px;", "width:220px;")
                                          .Replace("width:330px;", "width:200px;")
                                          .Replace("font-size:10pt;font-family:Verdana;", "font-size:8pt;font-family:Arial Unicode MS;")
                                          .Replace("\r\n", String.Empty);

This gave me the desired format of the NestedViewTemplate items

 

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