Search code examples
csvdatatablestabletools

jQuery DataTables - File becomes empty after dynamic change of filename


I want to dynamically change my exported CSV file name.

accountsDataTable = $('#accounts-list').DataTable({
    "dom": 'Tlfrtip',
    "tableTools": {
        "sSwfPath": "swf/copy_csv_xls.swf",
        "aButtons": [{
            "sExtends": "csv",
            "sTitle": "Temporaire",
            "sButtonText": "Exporter en CSV",
            "mColumns": "visible",
            "fnClick": function ( nButton, oConfig, oFlash ) {
                oFlash.setFileName("MonNomDeFichier.csv");
            }
        }]
    },
}

This does change the file name but the content is missing. I think fnClick function is missing this.fnSetText but I don't know what to put in it ?!


Solution

  • Try:

    "fnClick": function ( nButton, oConfig, oFlash ) {
                  oFlash.setFileName("MonNomDeFichier.csv");
                  this.fnSetText( oFlash, this.fnGetTableData(oConfig) );//Add this after your code, since you have overridden the original code 
               }
    

    Check here for more info : http://datatables.net/forums/discussion/10248/fnclick-callback-on-tabletools-flash-button-breaks-csv-xls-export