How to use csv customize option in dattable export csv button?

How to use csv customize option in dattable export csv button?

jimilsumrajimilsumra Posts: 3Questions: 1Answers: 0

Hi,

Please help me with my question as I am trying to put header and footer in my csv when trying to export datatable data through csv.

I have already asked my question here: http://stackoverflow.com/questions/39988562/how-to-add-custom-header-or-title-and-footer-information-of-company-in-csv-expor

Like following example: I don't know what I have to pass customize: function(here other than doc)
{
extend: 'csvHtml5',
customize: function (document) {
document.content.splice(1, 0, {
margin: [0, 0, 0, 12],
alignment: 'center',
image: 'data:image/png;base64,iVBOJggg=='
});
}
}

Thanks any help would be really helpful.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    If you want to include the footer, just use:

    {
      extend: 'csvHtml5',
      footer: true
    }
    

    I don't really understand why you've included a pdf customize function for your CSV button? The CSV customize callback is not the same as the pdf one.

    Allan

  • jimilsumrajimilsumra Posts: 3Questions: 1Answers: 0
    edited October 2016

    Hi allan,

    What I was trying to do is put header and footer or say one paragraph before table data and one paragraph after table data. So how I can add that in CSV or Excel export format??

    and as it's define in a document that I can use customize function so I wanted to try that out but did not work:(

    {
                    extend: 'csvHtml5',
                    customize: function (document) {
        
                    }
                }
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Oh I see - a text header / footer rather than the table's header and footer!

    With the CSV export its fairly easy:

    {
      extend: 'csvHtml5',
      customize: function (csv) {
         return "My header\n\n"+  csv;
      }
    }
    

    With the Excel file its a heck of a lot more complex. The customize callback for the Excel output gives you an object that contains the XML files for the XLSX format. You will need to look up the Open Spreadsheet documentation for how to insert new data into the file. I'm afraid I don't have a simple example of that.

    Allan

  • jimilsumrajimilsumra Posts: 3Questions: 1Answers: 0

    Hi Allan,

    Thank you so much for your lovely answer.:) and also sorry for late response.I'll check this out.

This discussion has been closed.