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

[Solved] Export to PDF not displaying unless ignore paging=true

6 Answers 348 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 08 Jan 2010, 07:38 PM
Hi all,

I am using the latest build and service pack of RC for ajax, and using a grid. I am using custom export buttons to export to pdf, excel and word. Excel and Word work, no problem. The pdf does not work unless i set the ignore paging=true, otherwise I receive a blank page.

I am using advancing sorting/paging with the needdatasource event. The grid functions perfectly in all respects except for the export to pdf.

Any help is much appreciated.

P.S. - as a side note, the grid is ajaxified, although the export buttons are not, although I do not think that has anything to do with it considering it works for Word and Excel in all cases.

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Jan 2010, 09:57 PM
Hello Kurt,

Could you please post some code that illustrate your approach? In the meantime please try to rebind RadGrid before exporting to PDF and let me know whether this helps.
protected void PdfExport_Click(object sender, EventArgs e)
{
    RadGrid1.Rebind();
    RadGrid1.MasterTableView.ExportToPdf();
}

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jeff
Top achievements
Rank 1
answered on 11 Jan 2010, 03:30 PM

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)  
            If rgData Is Nothing Then Exit Sub  
            If rgData.Visible = False Then Exit Sub  
 
            rgData.MasterTableView.Columns.FindByUniqueName("EDITUNIT").Visible = False 
            rgData.MasterTableView.Columns.FindByUniqueName("REPRINTRECEIPT").Visible = False 
            MeMe.rgData.ExportSettings.IgnorePaging = Me.chkExportAll.Checked  
            Select Case sender.id  
                Case "btnPDFExport"  
 
                    rgData.ExportSettings.Pdf.PageHeight = Unit.Parse("216mm")  
                    rgData.ExportSettings.Pdf.PageWidth = Unit.Parse("297mm")  
                    rgData.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("10mm")  
                    rgData.ExportSettings.Pdf.PaperSize = GridPaperSize.Letter  
                    rgData.Rebind()  
                    rgData.MasterTableView.ExportToPdf()  
                Case "btnExcelExport"  
                    rgData.MasterTableView.ExportToExcel()  
                Case "btnWordExport"  
                    rgData.MasterTableView.ExportToWord()  
            End Select  
 
 
        End Sub 
Above is the code for the on-click of the Export buttons

Below is the markup for the grid itself
<telerik:RadGrid ID="rgData" runat="server" AutoGenerateColumns="False" GridLines="None" AllowCustomPaging="True" Skin="Windows7" 
                    AllowPaging="True" AllowSorting="True" GroupingEnabled="False" ShowStatusBar="True" OnItemCreated="rgData_ItemCreated" Width="1000" Visible="false">  
                    <ExportSettings  
                       ExportOnlyData="true" 
                       IgnorePaging="false" 
                       OpenInNewWindow="true">  
                         
 
                    </ExportSettings> 
                   <ClientSettings> 
                     
                        <Scrolling AllowScroll="True" UseStaticHeaders="true" ScrollHeight="500px" /> 
                        <Resizing  
                            AllowColumnResize="True" 
                            AllowRowResize = "false" 
                            ResizeGridOnColumnResize = "false" 
                            ClipCellContentOnResize = "true" 
                            EnableRealTimeResize = "false" /> 
 
                    </ClientSettings> 
                      
                                <MasterTableView DataKeyNames="UNIT_ID,SHIPMENT_ID,PUBLICTARIFF_FLG" ClientDataKeyNames="UNIT_ID,SHIPMENT_ID,PUBLICTARIFF_FLG" > 
                                  
 
                                    <Columns> 
                                    <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Unit #" SortExpression="UNITNBR" UniqueName="UNITNBR" HeaderStyle-Width="80px">  
                                         <ItemTemplate> 
                                            <asp:HyperLink ID="hypUnit" runat="server" Text='<%# Eval("UNITNBR") %>'></asp:HyperLink> 
                                            </ItemTemplate> 
                                        </telerik:GridTemplateColumn> 
                                        <telerik:GridBoundColumn AllowFiltering="False" DataField="STATUS" HeaderText="Status" UniqueName="STATUS"  HeaderStyle-Width="200px">  
                                        </telerik:GridBoundColumn> 
                                         <telerik:GridBoundColumn   
                                                    DataField="VESSEL_NAME"   
                                                    HeaderText="Barge"   
                                                    SortExpression="VESSEL_NAME" UniqueName="VESSEL_NAME" HeaderStyle-Width="60px"/>  
                                         <telerik:GridBoundColumn  
                                                    DataField="INITIALSAIL_DT"   
                                                    HeaderText="Sail Date"   
                                                    SortExpression="INITIALSAIL_DT" UniqueName="INITIALSAIL_DT"   
                                                     HeaderStyle-Width="60px"/>  
                                         <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Shipment" SortExpression="SHIPMENTNBR" UniqueName="SHIPMENTNBR" DataField="SHIPMENTNBR"  HeaderStyle-Width="50px">  
                                         <ItemTemplate> 
                                            <asp:HyperLink ID="hypShipment" runat="server" Text='<%# Eval("SHIPMENTNBR") %>'></asp:HyperLink> 
                                            </ItemTemplate> 
                                        </telerik:GridTemplateColumn>   
                                          
                                   
                                        <telerik:GridBoundColumn   
                                                    DataField="POL_NAME"   
                                                    HeaderText="Orig"   
                                                     UniqueName="POL_NAME" 
                                                    SortExpression="POL_NAME" 
                                                     HeaderStyle-Width="50px" /> 
                                         <telerik:GridBoundColumn  
                                                    DataField="POD_NAME"   
                                                    HeaderText="Dest"   
                                                     UniqueName="POD_NAME" 
                                                    SortExpression="POD_NAME" 
                                                     HeaderStyle-Width="50px" /> 
                                         <telerik:GridBoundColumn   
                                                    DataField="Shipper"   
                                                    HeaderText="Shipper"   
                                                     UniqueName="Shipper" 
                                                    SortExpression="Shipper"   
                                                     HeaderStyle-Width="100px"/>        
                                          <telerik:GridBoundColumn   
                                                    DataField="CONSIGNEE"   
                                                    HeaderText="Consignee"   
                                                     UniqueName="CONSIGNEE" 
                                                    SortExpression="CONSIGNEE" 
                                                     HeaderStyle-Width="100px" /> 
                                         <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Ntfd" SortExpression="NOTIFIED" UniqueName="NOTIFIED" DataField="NOTIFIED"  HeaderStyle-Width="30px">  
                                         <ItemTemplate> 
                                            <asp:HyperLink ID="hypNotified" runat="server" Text='<%# Eval("NOTIFIED") %>'></asp:HyperLink> 
                                            </ItemTemplate> 
                                        </telerik:GridTemplateColumn>   
                                         <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="" SortExpression="" UniqueName="REPRINTRECEIPT"  HeaderStyle-Width="60px">  
                                         <ItemTemplate> 
                                            <asp:HyperLink ID="hypReprintReceipt" runat="server" Text='Receipts'></asp:HyperLink> 
                                            </ItemTemplate> 
                                        </telerik:GridTemplateColumn> 
                                        <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="" SortExpression="" UniqueName="EDITUNIT" HeaderStyle-Width="60px">  
                                         <ItemTemplate> 
                                            <asp:HyperLink ID="hypEditUnit" runat="server" Text='Edit Unit'></asp:HyperLink> 
                                            </ItemTemplate> 
                                        </telerik:GridTemplateColumn> 
                                          
                                    </Columns>   
                              <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" AlwaysVisible="true"/>        
                 
                                </MasterTableView> 
 
                            </telerik:RadGrid> 
And in case you need it, here is the ajaxmanager code...

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="btnSearch">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="lblMessage" /> 
                            <telerik:AjaxUpdatedControl ControlID="rgData" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 

The grid is based on a set of criteria, and is populated when a SEARCH button is clicked, which causes the Grid to become visible, and bound. All other exports work fine other than the PDF, which also works fine if IGNORE PAGING is true (all records). I have tried it with the rebind method and without and in both cases, a blank PDF is created if IGNORE PAGING is false.

Lastly, if you need it, here is the NEEDDATASOURCE code
Protected Sub rgData_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgData.NeedDataSource  
            Try  
                Dim dsOutput As DataSet  
                Dim dblib As New dsShipment  
                Dim lCurrentRecord As Integer = 0 
                Dim lPageSize As Integer = 0 
                Dim sSortBy As String = "" 
                Dim sSortOrder As String = "A" 
                Dim sOnlyActiveBookings As String = "N" 
                Dim sStartDate As String = "" 
                Dim sEndDate As String = "" 
                Dim Colexpression As Telerik.Web.UI.GridSortExpressionCollection  
                Dim expression As Telerik.Web.UI.GridSortExpression  
 
                'If Not IsPostBack Then Exit Sub  
                'Me.pnlExport.Visible = True 
                Colexpression = rgData.MasterTableView.SortExpressions  
                If Colexpression.Count <> 0 Then  
                    expression = Colexpression.Item(0)  
                    sSortBy = expression.FieldName  
                    sSortOrder = IIf(expression.SortOrder = Telerik.Web.UI.GridSortOrder.Ascending, "A", "D")  
                End If  
                lPageSize = rgData.PageSize  
                lCurrentRecord = rgData.CurrentPageIndex * lPageSize  
                If Me.chkShowActive.Checked Then sOnlyActiveBookings = "Y" 
                If Me.ucBookingFromDate.hasValue Then sStartDate = Me.ucBookingFromDate.DateValue  
                If Me.ucBookingToDate.hasValue Then sEndDate = Me.ucBookingToDate.DateValue  
                ' sSortOrder = rgData.Sort  
 
                dsOutput = dblib.GetShipmentTrackingResultsAdvanced(txtShipmentNbr.Text, txtUnitNbr.Text, Me.ucCompanyNameShipper.SelectedValue, _  
                                                    Me.ucConsignee.SelectedValue, sOnlyActiveBookings, sStartDate, sEndDate, sSortBy, ViewState("SortOrder"), _  
                                                    lCurrentRecord, lPageSize)  
 
                rgData.VirtualItemCount = dblib.RecordCount  
                rgData.DataSource = dsOutput.Tables(0)  
                If Not Me.bEditUnitRight Then  
                    rgData.Columns(11).Visible = False 
                End If  
                If Not Me.bReprintReceiptsRight Then  
                    rgData.Columns(10).Visible = False 
                End If  
            Catch ex As Exception  
 
            End Try  
        End Sub 
Thanks for the help
0
Jeff
Top achievements
Rank 1
answered on 13 Jan 2010, 04:41 PM
Bump to see if anyone has any ideas on how to fix this issue...
0
Daniel
Telerik team
answered on 13 Jan 2010, 05:07 PM
Hello Kurt,

Please disable the StaticHeaders as shown below:
...
rgData.ExportSettings.Pdf.PaperSize = GridPaperSize.Letter 
rgData.ClientSettings.Scrolling.UseStaticHeaders = false
rgData.Rebind()
...

Kind regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jeff
Top achievements
Rank 1
answered on 13 Jan 2010, 05:16 PM
Thanks Daniel, that did the trick.

Something to keep in mind (for anyone else with a similar problem) is that you do not want to rebind or set the static headers if you are exporting all. Only if you are exporting what is seen. So for instance in my code I check to see if they are exporting all (ignoring paging)...


 

If Not Me.chkExportAll.Checked Then ' (if the user is only exporting what is seen)

 

    rgData.ClientSettings.Scrolling.UseStaticHeaders =

False

 

    rgData.Rebind()

 

End If

Thanks again Daniel.

 

0
Daniel
Telerik team
answered on 13 Jan 2010, 06:14 PM
Hello Kurt,

I'm glad that my suggestion was helpful.
We decided to describe this scenario in PDF export help topic the next time we update the documentation.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or