Export to a file with a custom file name

Export to a file with a custom file name

dthemesdthemes Posts: 11Questions: 6Answers: 0

Hi,

I tried to export DataTable data to a file with a custom file name. However, whatever I try the file name is always set to the title of the web page.

Please see my code below:

$.getJSON("http://127.0.0.1:9999/getdata", function( raw ) {
  $(document).ready(function() {
    $('#data').html( '<table cellpadding="0" cellspacing="0" border="0" class="display compact" id="foo-data"></table>' );
 
    $('#foo-data').dataTable( {
      dom: '<"tblContainerT"T><"tblContainerTop"lf><rt><"bottom"ip>',
      sSwfPath: "/swf/copy_csv_xls_pdf.swf",
      buttons: [
        {
          extend: 'excelFlash',
          title:  'Data export'
        }
      ],
      data: raw['tbody'],
      columns: raw['thead']
    });
  });
});

Cheers

Answers

  • dthemesdthemes Posts: 11Questions: 6Answers: 0

    bump

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    You are using both TableTools and Buttons in the above configuration. I would suggest not using TableTools at all.

    Allan

  • dthemesdthemes Posts: 11Questions: 6Answers: 0

    Hi,

    Ok I understand. But I don't know what you call "TableTools". Is the "dataTable" function ?

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    Don't use the T in the dom parameter - that is TableTools. But the B for buttons. See the Buttons documentation for defaults.

    Allan

This discussion has been closed.