2016-12-01 71 views
2

我試圖導出基於jQuery數據表中的數據的CSV文件,我希望它排除第一列數據,這裏是我當前的腳本。忽略數據表中的第一列CSV導出

<script> 
$(document).ready(function() { 
$('#example').DataTable({ 
    dom: 'Bfrtip', 
    lengthMenu: [ 
     [ 10, 25, 50, -1 ], 
     [ '10 rows', '25 rows', '50 rows', 'Show all' ] 
    ], 
    buttons: [ 
     'copy', 'csv', 'excel', 'pdf', 'print', 'pageLength' 
    ] 
}); 
}); 
</script> 

什麼我需要添加到得到那個工作,請

回答

4

您需要使用您的exportOptions定義buttons內。

buttons: [ 
     { 
      extend: 'pdf',   
      exportOptions: { 
       columns: [1,2,3,4] // indexes of the columns that should be printed, 
      }      // Exclude indexes that you don't want to print. 
     }, 
     { 
      extend: 'csv', 
      exportOptions: { 
       columns: [1,2,3,4] 
      } 

     }, 
     { 
      extend: 'excel', 
      exportOptions: { 
       columns: [1,2,3,4] 
      } 
     }   
    ]