Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

837
Vistas
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 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

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 4 years ago · Santiago Trujillo Denunciar

0

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

doc.styles.tableBodyOdd.noWrap = true;
doc.styles.tableBodyEven.noWrap = true;
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda