Dynamically changing the file name of jquery Datat

2019-02-27 09:28发布

From 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.

1条回答
小情绪 Triste *
2楼-- · 2019-02-27 09:55

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';

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

查看更多
登录 后发表回答