使用按钮api动态更改导出excel的jquery数据表的文件名

来自Api:

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

这正在改变标题,但导出现在不起作用。 任何建议或解决方法都会有所帮助。

请参阅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