修改数据表工具在运行时的默认PDF导出文件名

时间:2022-06-21 11:42:46

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.

我正在使用JQuery DataTables TableTools插件,并为PDF定义一个默认文件名。但是,我在使用ajax中的datatable,并有一个日期范围选择器,因此页面不会刷新,因此当随后的条件更改时,我无法提供新的默认文件名。

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?

有谁知道在使用表工具初始化datatables后,我如何在运行时更改默认文件名?e直接修改配置?

                "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"
                ]

            }

1 个解决方案

#1


9  

I guess you want some dynamically generated name. Create a function that returns the (string) file name.

我猜你想要一些动态生成的名字。创建返回(string)文件名的函数。

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({ }).

并使用$(document)中的函数。准备好了但外(# dTable)美元。数据表({ })。

"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"
                ]

            }

#1


9  

I guess you want some dynamically generated name. Create a function that returns the (string) file name.

我猜你想要一些动态生成的名字。创建返回(string)文件名的函数。

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({ }).

并使用$(document)中的函数。准备好了但外(# dTable)美元。数据表({ })。

"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"
                ]

            }