开发者

Modify DataTables TableTools default PDF export filename at runtime

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开发者_如何学JAVA, 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"
                ]

            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜