Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Table customising pdf

I am using jQuery Data Table to export table as pdf.Now the pdf all the text are left aligned.How can I change it to right aligned?I need to add custom css to the exported pdf.

Here is my code

$('#reporTable').DataTable({

    "paging" : false,
    "ordering": false,
    "info" : false,
    "searching" : false,

    dom: 'T<"clear">lfrtip',
    tableTools: {
    "sSwfPath": "/javascripts/js/dataTables/tools/swf/copy_csv_xls_pdf.swf",

    "aButtons": [
    {
    "sExtends": "pdf",
    "sTitle": filename,
    "sPdfOrientation": "landscape",
    "sPdfMessage": out_name+":" + msg
    },

    ],

    }

    });
like image 913
Bibin Joseph Avatar asked Mar 11 '23 20:03

Bibin Joseph


1 Answers

Use the customize callback. It is not so well documented, see this answer for some references, or you could simply try to investigate the passed doc literal yourself. Basically

customize: function(doc) {
  doc.defaultStyle.alignment = 'right';
  doc.styles.tableHeader.alignment = 'right';
}

will end up in a PDF with right aligned headers and cell content. A sample could be

$('#example').DataTable( {
  dom: 'Bfrtip',
  buttons: [{
   extend: 'pdfHtml5',
   customize: function(doc) {
     doc.defaultStyle.alignment = 'right';
     doc.styles.tableHeader.alignment = 'right';
   }  
 }]
})

demo -> https://jsfiddle.net/yzdtLz36/

like image 176
davidkonrad Avatar answered Mar 28 '23 05:03

davidkonrad