Please help me to add page break in Print and PDF output before a specific row.
Please help me to add page break in Print and PDF output before a specific row.

Code:
echo "<script>
$('#batchTable').DataTable(
{
dom: 'Bfrtip',
destroy: true,
ordering: false,
bLengthChange: false,
bInfo: false,
/* createdRow: function( currentNode){
alert(currentNode.id);
},
*/
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
alert('in pageBreakBefore');
return currentNode.id == 'branchrow';
},
buttons: [
{extend: 'excel',
title: function() {
return 'Music Institute, Pune Batchwise Student List Date: ' + document.getElementById('dttoday').value;
},
filename: 'Batchwise Student List'},
{extend: 'pdf',
title: function() {
return 'Music Institute, Pune Batchwise Student List Date: ' + document.getElementById('dttoday').value;
},
filename: 'Batchwise Student List',
customize: function(doc) {
doc.styles.title = {
fontSize: '12',
bold: false
},
doc.styles.tableHeader = {
alignment: 'left'
},
doc['footer']=(function(page, pages) {
return {
columns: [
'',
{
alignment: 'right',
text: [
'page ',
{ text: page.toString(), italics: true },
' of ',
{ text: pages.toString(), italics: true }
]
}
],
margin: [10, 0]
}
});
},
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
alert('in pageBreakBefore');
return currentNode.id == 'branchrow';
}
},
{extend: 'print',
title: function() {
return 'Music Institute, Pune Batchwise Student List Date: ' + document.getElementById('dttoday').value;
},
customize: function(doc) {
$(doc.document.body).find('h1').css('font-size', '15pt');
},
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
alert('in pageBreakBefore');
return currentNode.id == 'branchrow';
}
}]
} );
</script>";
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I have a datatable that shows batches and students in those batches. I am printing batch number and other details of the batch in a separate row when the batch changes. This row is not a header row.
I want to insert a page break in the Print or PDF output when a new Batch starts.
Sample output:
Sr StudentName CourseName StartDate LastDate -> header row
Branch: Branch 1
Batch 1 Teacher: Mr. Kacheshwar Mudgaleshwar Tulshibagwale Subject: Vocal Classical
Mon 10:30-11:30, Tue 16:00-18:00, Thu 14:20-15:20
1 Mr. Parag Sathe Praveshika Pratham 18/08/2020
2 Mr. Sooraj Galgale Praveshika Purna 24/09/2020
3 Mrs. Suhasini K Sane Praveshika Pratham 24/09/2020
4 Mrs. Sulakshana P Pandit Praveshika Pratham 24/09/2020
5 Ms. Nikita Raysoni Madhyama Pratham 24/09/2020
************** I want a page break here in the Print of PDF outputs *************id of the following TR is 'branchrow'
Branch: Branch 1
Batch 2 Teacher: Mrs. Kalpana Ayyar Subject: Bharatnatyam 01/04/2020 01/10/2020
Mon 10:00-12:00, Wed 16:00-18:00
1 Mrs. Suhasini K Sane Praveshika Pratham 06/10/2020
2 Mrs. Sulakshana P Pandit Praveshika Pratham 06/10/2020
Answers
Sample output attached
This thread on pdfmake might point you in the right direction - you'll need to do something like that. I don't have an example, unfortunately,
Colin
Thanks for the response, I want to add page break before a specific table row that has the subheadings. I am not sure how to specify a page break there.
I tried things like createdRow, pageBreakBefore function; but none of them worked. createdRow shows alert, but doesn't add a page break.
// $(row).css('page_break-before', 'always');
// $(row).css('pageBbreak', 'before');
}
},
I'm sorry, I'm not clear on how to do that. You would need to reference the pdfmake documentation.
Colin