Change Align Export Title, Top Message and Bottom Message

Change Align Export Title, Top Message and Bottom Message

conandatatableconandatatable Posts: 5Questions: 1Answers: 0

How do I change align and font style for export title, top message and bottom message? The export title, top message and bottom message keep show in center when I export Excel or PDF file. Here is my code.

buttons: [
       {
              "extend": 'excelHtml5',
              "className": 'btn btn-table-excel',
              "init": function( api, node, config) {
                        $(node).removeClass('dt-button')
              },
              "title": exportTitle,
              "messageTop": exportMessageTop,
              "messageBottom": exportMessageBottom
       }, {
              "extend": 'pdfHtml5',
              "className": 'btn btn-table-pdf',
              "init": function( api, node, config) {
                       $(node).removeClass('dt-button')
              },
              "title": exportTitle,
              "messageTop": exportMessageTop,
              "messageBottom": exportMessageBottom
       }
],

My DataTables version is 1.10.13 and my DataTables Buttons version is 1.6.1

Answers

  • conandatatableconandatatable Posts: 5Questions: 1Answers: 0
    edited January 2020

    exportTitle, exportMessageTop, exportMessageBottom is javascript variable

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This thread shows how to change the font in the PDF export. For the alignment, you'll need to modify the pdfmake document that has been created (a bit like you already are for the image) to add that padding. The pdfmake documentation would be where to start.

    For Excel, this thread should help.

    Colin

  • conandatatableconandatatable Posts: 5Questions: 1Answers: 0

    Sorry before. I still newbie in datatables and pdfmake. Is that mean I need to install pdfmake so I can customize the alignment and its other style?

    For Excel thread, I found the answer about changing font style. How about the alignment?

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Yep, you need PDFmake anyway, so that needs to be in your sources.

    Not sure about alignment in Excel, but again, you'll need to traverse through the document - this thread may help.

    Colin

  • conandatatableconandatatable Posts: 5Questions: 1Answers: 0

    Thank you. I will try it first. :)

  • conandatatableconandatatable Posts: 5Questions: 1Answers: 0

    I successfully changed align of exported excel title, top message and bottom message by adding this code. Thank you for giving me that thread @colin .

    "customize": function(xlsx) {
        var sheet = xlsx.xl.worksheets['sheet1.xml'];
        $('row:eq(0) c', sheet).attr('s','50');
        $('row:eq(1) c', sheet).attr('s','50');
        $('row:last c', sheet).attr('s','50');
    }
    
This discussion has been closed.