Chr*_*ris 5 javascript jquery datatables
我正在使用JQuery DataTables TableTools插件,并定义了PDF的默认文件名.但是,我使用带有ajax的数据表,并且有一个日期范围选择器,因此页面没有刷新,因此当条件更改时,我无法提供新的默认文件名.
有没有人知道如何在使用表工具初始化数据表之后在运行时更改默认文件名,即直接修改配置?
"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"
]
}
Run Code Online (Sandbox Code Playgroud)
我想你想要一些动态生成的名字.创建一个返回(字符串)文件名的函数.
function getCustomFileName(){
var docDate = $("#from").val();
var filter = $("#example_filter input").val();
var oSettings = oTable.fnSettings();
var fileName = docDate+"_"+filter;
return fileName;
}
Run Code Online (Sandbox Code Playgroud)
并使用内部$(document).ready但外部的功能$('#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"
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15988 次 |
| 最近记录: |