Exclude column from export in jQuery Datatables

Try using CSS selector that excludes last column for columns option.

$('#reservation').DataTable({
   dom: 'Bfrtip',
   buttons: [
      {
         extend: 'excel',
         text: 'Export Search Results',
         className: 'btn btn-default',
         exportOptions: {
            columns: 'th:not(:last-child)'
         }
      }
   ]
});

You can add a class:

<th class='notexport'>yourColumn</th>

then exclude by class:

$('#reservation').DataTable({
   dom: 'Bfrtip',
   buttons: [
   {
        extend: 'excel',
        text: 'Export Search Results',
        className: 'btn btn-default',
        exportOptions: {
            columns: ':not(.notexport)'
        }
    }]
});

Tags:

Datatables