Search code examples
datatables

Exclude column from export in jQuery Datatables


I'm using jQuery datatable 1.10.11 and it's export button functionality as described here:

I want to skip last column from being export into excel file as this column has edit/delete buttons in it. My columns are generated dynamically so I can't use following method:

    $('#reservation').DataTable({
    dom: 'Bfrtip',
    buttons: [
        {
            extend: 'excel',
            text: 'Export Search Results',
            className: 'btn btn-default',
            exportOptions: {
                columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
            }
        }
    ]
});

I know this question is asked multiple time but non of them worked for me, might be version issue.


Solution

  • 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)'
             }
          }
       ]
    });