2016-11-23 7 views
2

を使用してExcelをエクスポート:はAPIからボタン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(E、DT、ボタン、設定を)ありがとう。この行は助けになりました:) – user3231742

関連する問題