Export grid to pdf with page break per group

I'd like to be able to export a grid to pdf with a page break after each group. If there are multiple groups, it would just break after the first group definition (i.e., the outermost group). Is that possible?

Thank you.


9 Replies

BS Balaji Sekar Syncfusion Team December 16, 2021 12:46 PM UTC

Hi Bill, 

Currently we do not have support for export a Grid to PDF with a page break after each group and we can only exporting the Grid in grouping order to PDF document. 

Regards, 
Balaji Sekar. 



BN Bill Naples December 16, 2021 01:01 PM UTC

Hi Balaji, Thanks for the reply. Are there any hooks, events, or other intercepts we can use to programatically do this? Like for example, we implemented similar functionality when printing the grid by using the beforePrint event, as follows:


pageBreakAfterEachOuterGroup is called by beforePrint:

pageBreakAfterEachOuterGroup (gridEl) {
// This solution is based on the following stackoverflow answer:
// https://stackoverflow.com/a/45089106/1237919
for (const caption of gridEl.querySelectorAll('.e-gridcontent tr:not(:first-child) .e-groupcaption')) {
const tr = caption.parentNode
// The html doesnt't queryable indicators of the group level, so we'll need to check that here with
// more complex logic. All inner groups have at least one indent cell.
const isInnerGroup = tr.firstChild.classList.contains('e-indentcell')
if (isInnerGroup) continue

const pageBreakRow = document.createElement('tr')
pageBreakRow.className = 'page-break'

// On Chrome, simply styling the doesn't work.
// We need to insert into the a single containing these divs,
// and style the last
to page break.
if (window.chrome) pageBreakRow.innerHTML = '
'

tr.parentNode.insertBefore(pageBreakRow, tr)
}

// Remove footer table, i.e. grand total row, when printing page per group.
const footerTable = gridEl.querySelector('.e-gridfooter')
if (footerTable) footerTable.parentNode.removeChild(footerTable)
}




BS Balaji Sekar Syncfusion Team December 20, 2021 03:46 AM UTC

Hi Bill, 

Before proceeding your query, we need to confirm that you need to Print the Grid with a page break after each group so, please ensure this as your exact requirement then we will validate further. 

Regards, 
Balaji Sekar. 



BN Bill Naples February 22, 2022 08:15 PM UTC

Hi Balaji, Sorry for the slow reply. Yes I need a page break after each outer group. For example, if the grid is grouped by field1, field2, and field3 (in that order), then there should be a page break after each group of field1 only. Is that possible?


Thanks.



SK Sujith Kumar Rajkumar Syncfusion Team February 24, 2022 02:04 PM UTC

Hi Bill, 
 
We are currently validating the query from our end and we will provide the further details on or before 1st March 2022. 
 
Until then your patience is appreciated. 
 
Regards, 
Sujith R 



SK Sujith Kumar Rajkumar Syncfusion Team February 25, 2022 01:03 PM UTC

Hi Bill, 

Thanks for your patience. 

We validated this case further by implementing your shared code for applying breaks on printing the Grid in order to understand your requirement better. But we could not see any breaks applied using the shared solution. Please check the below TS Grid sample where this case is demonstrated for reference, 


So can you please share us a pictorial or video demonstration of the Grid printed document(to be clear on the exact requirement) and if possible implement your use case in the above shared sample to validate further on this. 

Regards, 
Sujith R 



BN Bill Naples February 25, 2022 07:21 PM UTC

Hi Sujith,


Page break by group works on the following stackblitz:

https://stackblitz.com/edit/k1q7ik-shguma?file=index.ts

Just group Country column to grouping header, and print.


The two changes I had to make to your stackblitz are:

1) Change the following line of code:

pageBreakRow.innerHTML = '<td><div></div><div></div></td>';

It seems that the html tags didn't display properly in my previous post.

2) Add css to index.html for the page break.



SK Sujith Kumar Rajkumar Syncfusion Team February 28, 2022 12:53 PM UTC

Hi Bill, 
 
Thanks for sharing the modified sample demonstrating your use case. 
 
We are currently validating the feasibility of achieve this from our end and we will provide you the further details on or before 2nd March 2022. 
 
Until then your patience is appreciated. 
 
Regards, 
Sujith R 



SK Sujith Kumar Rajkumar Syncfusion Team March 1, 2022 09:21 AM UTC

Hi Bill, 

Thanks for your patience. 

We validated this case further from our end and would like to inform to you that we cannot achieve page break for each grouped grid row while exporting to pdf document. This is because we can only paginate the entire Pdf Grid based on the current page size and grid bounds based on which the layout format will paginate the grid content. So it is not feasible to achieve your requirement of page break for each group record in our pdf Grid rendering approach. 

Regards, 
Sujith R 


Loader.
Up arrow icon