Dynamically changing the file name of jquery Datatables exported excel using buttons api

后端 未结 1 1236
暗喜
暗喜 2021-01-21 21:00

From Api:

$(\'#myTable\').DataTable( {
    buttons: {
        buttons: [
            {
                text: \'Alert\',
                action: function ( e, dt,         


        
1条回答
  •  时光说笑
    2021-01-21 21:47

    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

    0 讨论(0)
提交回复
热议问题