忽略数据表CSV导出中的第一列

Web*_*own 3 jquery datatables

我正在尝试根据jQuery数据表中的数据导出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>
Run Code Online (Sandbox Code Playgroud)

请告诉我需要添加什么来实现这一点

Raj*_*ddy 8

您需要exportOptionsbuttons定义中使用.

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] 
            }
       }         
    ]  
Run Code Online (Sandbox Code Playgroud)


pba*_*ney 6

接受的答案很好,但如果您不确定需要导出的列数,则可以使用另一种方法:

buttons: [
    {
        extend: 'excel', 
        exportOptions: {
            columns: ':gt(0)' 
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

第一列由偏移量 0 指定,因此此代码表示导出大于 0 的任何列(即,除第一列之外的所有其他列)。