Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore first column in datatables CSV export

I'm trying to export a CSV file based on data from jQuery datatables and I would like it to exclude the first column of data, here is my current script.

 <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>

What do I need to add to get that to work, please

like image 969
Webbly Brown Avatar asked Dec 01 '16 13:12

Webbly Brown


1 Answers

You need to use the exportOptions within your buttons definition.

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] 
            }
       }         
    ]  
like image 171
Rajshekar Reddy Avatar answered Oct 03 '22 08:10

Rajshekar Reddy