Buttons - Hide columns by default when exporting
Buttons - Hide columns by default when exporting
Hi there,
I'm trying to find out if it's possible to hide columns by default, when exporting data via buttons
. Preferably by setting classes or data attributes on the headings like below example of disabling sorting/ordering.
settings.columnDefs = [
{
"targets": 'dt-nosort',
"orderable": false,
},
];
I know that there is the colvis
option, but we don't want our users to have to disable certain columns before exporting, only to have to enable them again after exporting, to make use of the functionality in these columns. In our case we want to hide columns that e.g. contain action buttons on that row, so we can just show the actual data.
So something like this:
settings.columnDefs = [
{
"targets": 'dt-no-export',
"button-export": false,
},
];
Is this possible?
This question has an accepted answers - jump to answer
Answers
Maybe this example will help:
https://datatables.net/extensions/buttons/examples/html5/columns.html
Kevin
Thanks Kevin! Works like a charm, snippets of my solution using jQuery to select the columns:
Before initialising:
The method:
Will have to add some
$.extend
logic later if needed