How can align only one column in pdfhtml5 export?

How can align only one column in pdfhtml5 export?

anguswildanguswild Posts: 4Questions: 1Answers: 1

I have managed to edit the pdf export but i need to align only one column

i searched in this forum and in the pdfmake documentarion but i haven't find how to do it. Please help!

My customize function is the following

              customize: function ( doc ) {
                    doc['footer']=(function(page, pages) {
                        return {
                            columns: [
                            '*',
                            {
                            alignment: 'right',
                            text: [
                            { text: page.toString(), italics: true },
                            ' de ',
                            { text: pages.toString(), italics: true }
                            ]
                            }
                            ],
                        margin: [30, 0]
                        }
                    });
                    var d = new Date();
                    var fecha = d.toLocaleDateString('es-CL');
                    var hora = d.toLocaleTimeString('es-CL');
                    doc.content.splice( 1, 0, {
                        
                        columns: [
                            {
                                alignment: 'left',
                                text: 'Comercial del Real \n Ramón Freire 471, Rancagua \n\n',
                                bold: true,
                            },
                            {
                                alignment: 'right',
                                text: 'Fecha: '+fecha+'\nHora: '+hora+'     ',
                                margin: [ 0, 0, 40, 0 ],
                                bold: true
                            }
                        ]
                    });
        
                }

Can i do something like this?

doc.content[1].table.alignment = [ 'left', 'right', 'left' ];

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin

    I honestly don't know myself. This is one for the pdfmake support channels rather than DataTables specific support.

    Allan

  • anguswildanguswild Posts: 4Questions: 1Answers: 1

    i managed to do it this way, but only aligns the header

    any idea in how can i do it for the entire column?

    doc.content[1].table.body[0][5].alignment = 'right';
    
  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin

    As I say, that's a pdfmake specific question.

  • anguswildanguswild Posts: 4Questions: 1Answers: 1
    Answer ✓

    I came up with a workaround

    var rowCount = document.getElementById("tableID").rows.length;
               for (i = 0; i < rowCount; i++) { 
                   doc.content[1].table.body[i][5].alignment = 'right';
                };
    

    I don't know if it is the best solution but it worked for me

    Have a nice day!

This discussion has been closed.