PROJECT DESCRIPTION
When exporting to PDF by using RadClientExportManager you may sometimes need to add hard page-breaks in the current grid so that a certain number of rows are displayed on different pages in the exported file.
Left picture shows an example of RadGrid with 20 items across 2 pages, right picture show the result of the exported file when exporting all records across all pages and applying page-break.
To do this, you need to traverse the rows and add the
page break selector to the desired rows.
The attached sample project demonstrates one way to do this. It also shows how you can export all the grid data across all pages to a PDF through the client-side export by disabling paging at the server level, which can be useful for generating small reports.
You could simply loop through the items and add the ',pageBreak' classname to the rows. In case, however, you would like to display the grid headers on each page, you can clone the header for each page.
Export to PDF with page-break
Here is an example of client-side method to apply page-break after specified amount of rows as well clones the Grid header.
Create a function that will call the exportPDF method of the ClientExportManager.
With a Button click, you can then apply page-break and export, like so:
Export with disabled Paging
To disable paging for the grid, a postback needs to be done. Since the ClientExportManager only operates on the client, you can send an
AJAX request to the server through the
RadAjaxManager.
Subscribe the AjaxManager to its AjaxRequest server-side event
AjaxRequest event handler
When the response is returned, the following method will be executed.
The above code will disable Paging and export the grid accordingly, but there is one more thing that needs to be done. Once the export has finished, return the paging so that the grid will display all the data in one page. To achieve that, you can subscribe the RadClientExportManager to its OnClientPdfExported client-side event.
In the event handler, send an AjaxRequest to the server and enable the paging.
RadAjaxManager's AjaxRequest event handler:
Well done!
I trust you have a better understanding on applying page-breaks to certain rows, export all records across all pages in the grid using RadClientExportManager.
Attached you can find the exported PDF file generated by the application as well the sample project resembling the above described scenario.