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

问题描述

来自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动态更改导出到excel的jquery数据表的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:12