2016-12-01 72 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] 
      } 
     }   
    ]