【问题标题】:Dynamically changing the file name of jquery Datatables exported excel using buttons api使用按钮api动态更改jquery Datatables导出的excel的文件名
【发布时间】:2016-11-23 07:04:37
【问题描述】:

来自 API:

$('#myTable').DataTable( {
    buttons: {
        buttons: [
            {
                text: 'Alert',
                action: function ( e, dt, node, config ) {
                    config.title ="dynamic title"
                }
            }
        ]
    }
} );

这正在更改标题,但现在无法导出。任何建议或解决方法都会有所帮助。

【问题讨论】:

    标签: jquery datatables


    【解决方案1】:

    请参阅https://datatables.net/forums/discussion/33209/run-script-before-exporting-begins-buttons-plugin 您需要以编程方式调用原始操作。小例子:

    $('#example').DataTable( {
       dom: 'Bfrtip',
       buttons: [{
          extend: 'excel',
          action: function(e, dt, button, config) {
            config.filename = dynamicVariable;
            $.fn.dataTable.ext.buttons.excelHtml5.action(e, dt, button, config);
          }
        }]   
    })   
    
    var dynamicVariable = 'qwerty';
    

    会产生一个qwerty.xslx 见-> https://jsfiddle.net/2ez9mxop/2

    【讨论】:

    • 谢谢,$.fn.dataTable.ext.buttons.excelHtml5.action(e, dt, button, config);这条线有帮助:)
    猜你喜欢
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    • 2011-06-29
    • 2016-01-13
    相关资源
    最近更新 更多