• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

730
Views
DataTables PDF export (pdfmake): how to prevent breaking rows in page breaks?

I am trying to customize the PDF-Export with DataTables (which uses pdfmake). All my custom styles are working except dontBreakRows, it doesn't seem to make any difference, so table rows contents are being splited in page breaks, instead of keeping them together on the next page when they don't fit in the previous, which is what I had expected.

My pdfmake version is 0.1.27 (last one, on the date), DataTables 1.10.12, Buttons 1.2.1

This is my code:

(...)
$.extend( true, {}, buttonCommon, {
    'extend': 'pdf',
    'text': 'PDF A4',
    'orientation': 'landscape',
    'pageSize': 'A4',
    'message': 'Date '+todays,
    'customize': function (doc) {
      doc.content.splice(1, 0, {
        margin: \{0, -32, 0, 8\},
        alignment: 'right',
        image: 'data:image/png;base64,(...)'
      });
      //These styles are working:
      doc.defaultStyle.fontSize = 10;
      doc.styles.title.fontSize = 12;
      doc.styles.tableHeader.fontSize = 11;
      doc.styles.tableFooter.fontSize = 11;
      doc.styles.tableHeader.alignment = 'left';
      doc.styles.title.bold = true;
      doc.styles.tableHeader.bold = true;
      doc.styles.tableHeader.color = '#ffffff';
      doc.styles.tableHeader.fillColor = '#666666';
      doc.styles.tableBodyOdd.fillColor = '#ffffff';
      doc.styles.tableBodyEven.fillColor = '#e9e9e9';
      doc.styles.tableHeader.noWrap = true;

      //It doesn't work:
      doc.styles.tableBodyOdd.dontBreakRows = true;
      doc.styles.tableBodyEven.dontBreakRows = true;
      doc.styles.tableBodyOdd.pageBreak = 'before';
      doc.styles.tableBodyEven.pageBreak = 'before';

      //It doesn't work neither:
      doc.defaultStyle = 
        {
          dontBreakRows: true
        }              
    }

}),
(...)

What am I doing wrong? Thank you!

about 3 years ago · Santiago Trujillo
2 answers
Answer question

0

I had exactly the same problem. The styles are not working.

For me this worked (depending on the table's position in content):

doc.content[1].table.dontBreakRows = true; 

If you figured out a better way, just let me know

about 3 years ago · Santiago Trujillo Report

0

You are using bodyOdd and bodyEven, so you need to use

doc.styles.tableBodyOdd.noWrap = true;
doc.styles.tableBodyEven.noWrap = true;
about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error