2016-11-23 51 views
2

從AP導出的Excel數據表的jQuery的文件名:動態改變使用按鈕API

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

這種情況正在改變標題,但出口不是現在的工作。任何建議或解決方法都會有所幫助。

回答

3

請參閱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

+0

謝謝$ .fn.dataTable.ext.buttons.excelHtml5.action(即,DT,按鈕配置);這條線幫助:) – user3231742