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

export radgrid in asp.net html page to pdf, lengthy table is not continuing in next page.

4 Answers 35 Views
ClientExportManager
This is a migrated thread and some comments may be shown as answers.
narendra
Top achievements
Rank 1
narendra asked on 25 Jul 2019, 12:39 PM

Dear Sir/Madam,

i am using telerik ajax dll version (Telerik.web.ui.dll) 2019.1.215.45 in asp.net application. i have dynamically created radgrid which has more than 70 rows, so when i am trying to export radgrid to pdf using RadClientExportManager [exporting html content to pdf]. The lengthy radgrid is not continuing to next page in pdf. the first 50 rows are printed in first page the rest of the rows are not getting printed in second page.

4 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 26 Jul 2019, 07:40 AM

Hello Narendra,

The page break export of the RadGrid needs custom implementation and taking into consideration the height of the row requires custom logic depending on the requirements.

Here is a CodeLibrary project that shows how to add the page break: https://www.telerik.com/support/code-library/page-for-client-side-export.

I have modified the addPageBreakSelectorsToGrid function to add a page break based on the height of the rows. Attached is the sample project I used to test this functionality.

//loop the grid elements and add page break selectors and also clone the headers
//you can modify further as needed, for example, just addClass to certain row elements
function addPageBreakSelectorsToGrid(itemsPerPage) {
    var grid = $find("<%=RadGrid1.ClientID%>");
    var items = grid.get_masterTableView().get_dataItems();
    var totalHeight = 0;
    for (var i = 1; i < items.length; i++) {
        var rowHeight = items[i - 1].get_element().getBoundingClientRect().height;
            totalHeight = totalHeight + rowHeight
        
        //if (i > 0 && i % itemsPerPage == 0) {
        if (totalHeight > 700) { // if the height exceeds the page height, add a pagebreak
            totalHeight = 0;
            //add a page break every nth item, you can use the original page size here if you like
            var breakRow = '<tr class="pageBreak">';
            //clone the header so the subsequent pages show a header to the consumer
            for (var j = 0; j < grid.get_masterTableView().get_columns().length; j++) {
                breakRow += '<td class="rgHeader">' + grid.get_masterTableView().get_columns()[j].get_uniqueName() + '</td>';
            }
            breakRow += '</tr>';
            $telerik.$(breakRow).insertAfter(items[i-1].get_element());
        }
    }
}

Let me know if you have any other questions related to the built-in functionality and API of our controls.

Regards, Peter Milchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
narendra
Top achievements
Rank 1
answered on 01 Aug 2019, 02:08 PM

Hi Peter,

thank you for you reply. for now I am using window.print(). let me try your reply in future and will get back to you. :)

0
narendra
Top achievements
Rank 1
answered on 01 Aug 2019, 02:09 PM
I think there should be a auto break mechanism. manually adding is a pain and extra code/work.
0
Peter Milchev
Telerik team
answered on 06 Aug 2019, 07:21 AM

Hello Narendra,

There is a built-in ClientSettings-EnableClientPrint functionality that autobreaks the Grid but does not add the headers on every page. 

Also, the ClientExportManager and the RadGrid are two different controls, so additional code is needed to achieve such a customization.

The good thing is that the code is already available and what you need to do to have the functionality is just to paste and reuse the code.

Regards, Peter Milchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ClientExportManager
Asked by
narendra
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
narendra
Top achievements
Rank 1
Share this question
or