本文介绍了使用按钮api动态更改jquery Datatables导出的excel的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 API:

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

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

This is changing the title, but export is not working now. Any suggestion or workaround will help.

推荐答案

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

See https://datatables.net/forums/discussion/33209/run-script-before-exporting-begins-buttons-plugin You need to call the original action programmatically. Small example :

$('#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

Will produce a qwerty.xslx see -> https://jsfiddle.net/2ez9mxop/2

这篇关于使用按钮api动态更改jquery Datatables导出的excel的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 21:07