I am using JQuery DataTables TableTools plugin and am defining a default filename for the PDF. However, I am using datatables with ajax, and have a date range selector, so the page isnt refreshed and therefore I am unable to provide a new default filename when then criteria changes.
Does anyone know how I can change the default filename at runtime, after datatables has been initialized with table tools, i.e modify the config directly?
"oTableTools": {
"sSwfPath": "js/DataTables/copy_cvs_xls_pdf.swf",
"aButtons": [
"copy",
"csv",
"xls",
{
"sExtends": "pdf",
"sTitle": "Report Name",
"sPdfMessage": "Summary Info",
"sFileName": "<?php print('How do i use jquery to change this after the table has been initialized'); ?>.pdf",
"sPdfOrientation": "landscape"
},
"print"
]
}
I guess you want some dynamically generated name. Create a function that returns the (string) file name.
function getCustomFileName(){
var docDate = $("#from").val();
var filter = $("#example_filter input").val();
var oSettings = oTable.fnSettings();
var fileName = docDate+"_"+filter;
return fileName;
}
And use the function inside $(document).ready
but outside $('#dTable').dataTable({ })
.
"oTableTools": {
"sSwfPath": "js/DataTables/copy_cvs_xls_pdf.swf",
"aButtons": [
"copy",
"csv",
"xls",
{
"sExtends": "pdf",
"sTitle": "Report Name",
"sPdfMessage": "Summary Info",
"sPdfOrientation": "landscape"
"fnClick": function( nButton, oConfig, flash )
{
customName = getCustomFileName()+".pdf";
flash.setFileName( customName );
this.fnSetText( flash,
"title:"+ this.fnGetTitle(oConfig) +"\n"+
"message:"+ oConfig.sPdfMessage +"\n"+
"colWidth:"+ this.fnCalcColRatios(oConfig) +"\n"+
"orientation:"+ oConfig.sPdfOrientation +"\n"+
"size:"+ oConfig.sPdfSize +"\n"+
"--/TableToolsOpts--\n" +
this.fnGetTableData(oConfig)
);
}
},
"print"
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With