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

Export to PDF when custom pagination is Enabled

4 Answers 291 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 13 Nov 2015, 01:12 AM

I have a radgrid with custom pagination enabled, so far all it's working as expected, I mean, each time that OnNeedDataSource event is fired, the grid datasource is updated with the needed data, in my case I have configured a PageSize = 10. So the problems comes when I'm trying to export to PDF, When the RadGrid pagination is in the first page, for example I have 15 items, so the first page is displaying just 10 items, then the export works fine, all items are well exported to pdf file, but if I go to the next page in the grid, in this case are showing the last 5 items in the second page, and I try to export to pdf, I 'm getting a blank pdf. How can I fix this ? some suggestion, please ? Just in case here some fragments of the code : 

<asp:View ID="ViewFiles" runat="server">
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" >
                 <telerik:RadGrid ID="RadGridFiles" runat="server" GridLines="None" TableLayout="Auto" Skin="Metro" PageSize="10"
                                AllowSorting="false" AllowMultiRowSelection ="false" AllowPaging="true"                                                            AllowCustomPaging="true" OnNeedDataSource ="RadGridFiles_NeedDataSource"                                            ShowStatusBar="True"  OnBiffExporting="grdSettings_BiffExporting" OnPdfExporting="grdSettings_PdfExporting">
                         <ClientSettings AllowDragToGroup="true">
                         </ClientSettings>
                        <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">                                                  </ExportSettings>
                         <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="True" />
                         <MasterTableView TableLayout="Fixed">
                                    <NoRecordsTemplate>
                                                           <div>
                                                               <asp:Label ID="lblNoResultDisplay" Text="There are no records to display" runat="server"
                                                                   CssClass="Label" meta:resourcekey="lblNoResultDisplayResource">
                                                               </asp:Label>
                                                           </div>
                        </NoRecordsTemplate>
                    </MasterTableView>
 
                </telerik:RadGrid>
      </telerik:RadAjaxPanel>
 </asp:View>
protected void btnExport_Click(object source, EventArgs e)
       {
 
 
           RadGridFiles.IsExportPDF = false;
           RadGridFiles.ExportSettings.FileName = string.Format("SDAR_{0}", tabValue);
           RadGridFiles.PageSize = RadGridFiles.MasterTableView.VirtualItemCount;
           RadGridFiles.ExportHeaderRow = new List<string>() { "Document Activity" };
 
           switch (fileTypeExport)
           {
               case "xml":
               case "xls":
                   RadGridFiles.ExportSettings.Excel.FileExtension = fileTypeExport;
                   RadGridFiles.ExportSettings.Excel.Format = (fileTypeExport == "xml") ? GridExcelExportFormat.ExcelML : GridExcelExportFormat.Biff;
                   RadGridFiles.MasterTableView.ExportToExcel();
                   break;
               case "pdf":
                   RadGridFiles.IsExportPDF = true;
                   RadGridFiles.ExportSettings.Pdf.PageHeight = Unit.Parse("300mm");
                   RadGridFiles.ExportSettings.Pdf.PageWidth = Unit.Parse("600mm");
                   RadGridFiles.ExportSettings.Pdf.PageHeader.LeftCell.Text = "<div style=\"font-size:14px;margin-left:70px;\"> LOGO </div>";
                   RadGridFiles.ExportSettings.Pdf.PageHeader.LeftCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Left;
 
                    
                   string dateText = string.Format("{0} - {1}"this.StartDate.ToString("MMMM dd, yyyy"), this.EndDate.ToString("MMMM dd, yyyy"));
 
                   RadGridFiles.ExportSettings.Pdf.PageHeader.RightCell.Text = "<div style=\"font-size:14px;margin-right:80px;\">" + dateText + "</div>";
                   RadGridFiles.ExportSettings.Pdf.PageHeader.RightCell.TextAlign = GridPdfPageHeaderFooterCell.CellTextAlign.Right;
                   RadGridFiles.PDFExportColWidths = new List<int>();
                   RadGridFiles.MasterTableView.ExportToPdf();
                   break;
           }
 
       }

4 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 17 Nov 2015, 10:46 AM
Hello Luis,

Thank you for contacting us.

Note that when using a custom paging you need to set the CurrentPageIndex to 0 and also set the page size to total number of items.
Another possible solution is to disable the paging when export to PDF command is fired in order to get all items from the datasource. Keep in mind the request is used only to generate the exported document and you do not need to enable the paging or change the page size and index afterwards.

Please give this suggestion a try and let me know about the result.

Regards,
Kostadin
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Luis
Top achievements
Rank 1
answered on 19 Nov 2015, 11:27 PM

I tried with the first option and it works for me. Thanks a lot :).

By other hand, just in case, do you know how much items is it possible to export ? I mean, if the page size has some limit at moment to export ? 

Thansk in Advance.

 

0
Accepted
Kostadin
Telerik team
answered on 24 Nov 2015, 12:54 PM
Hello Luis,

I am afraid an exact number of items could not be determine due to the many factors that affect export feature. Nevertheless, we strongly recommend to avoid exporting of large amount of data.

Regards,
Kostadin
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Luis
Top achievements
Rank 1
answered on 26 Nov 2015, 06:40 PM
Yes, I will follow the recomendation. Thanks a lot.
Tags
Grid
Asked by
Luis
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Luis
Top achievements
Rank 1
Share this question
or