Override default button export options?

Override default button export options?

jasper502jasper502 Posts: 25Questions: 9Answers: 0

Almost all my datatables have the last two columns that I don't want to print etc. I did this:

    $.extend($.fn.dataTable.defaults, {
      buttons: {
        buttons: [
          {
            extend: 'print',
            exportOptions: {
              columns: [':lt(-2)']
            }
          }
        ]
      }
    });

I have a default call on a class that loads the datatable.

Now I have the odd table that I want to clear this and print all columns. So I clear that class and manually initialize:

$('#odd_table').dataTable({
  buttons: {
    buttons: [
      {
        extend: 'print',
        text: '<i class="far fa-print"></i> Print',
        orientation: 'landscape',
        exportOptions: {
          columns: [0, 1]
        }
      }
    ]
  }
});

No mater what I specify in the exportOptions the default options are applied. I figured this was as easy as changing the default settings.

Answers

  • jasper502jasper502 Posts: 25Questions: 9Answers: 0

    That worked - some javascript issues on my end.

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    Your example code seems to work here:
    http://live.datatables.net/qucuqipo/1/edit

    Can you provide a link to your page or a test case showing the issue?

    Kevin

  • jasper502jasper502 Posts: 25Questions: 9Answers: 0

    It does work as I commented - I sure wish you could edit your posts.

    I would edit this to ask if you can override just the column exportOptions vs having to re-initialize all the button options.

This discussion has been closed.