Prevent a column from ever being exported to CSV, PDF, etc?
Prevent a column from ever being exported to CSV, PDF, etc?
Hello!
I have a table with an "Actions" column, which has buttons to edit, delete, etc. I don't want this to ever be exported to any format, even if it's visible to the user. Also, only visible columns have to be exported.
In the doc (https://datatables.net/extensions/buttons/examples/html5/columns.html), I discovered how to force export a column and how to hide it, but I don't know how to prevent it's export without the user having to hide the column.
My code is like this:
table = $('#merchants_server').DataTable({...
buttons: [
{
extend: 'colvis',
columns: ':not(.js-no-vis)',
text: 'CHOOSE COLUMNS',
className: 'btn btn-outline-primary'
},
{
extend: 'copy',
text: '<i class="fa fa-copy"></i>',
className: 'btn btn-outline-primary',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'csv',
className: 'btn btn-outline-primary',
exportOptions: {
columns: ':visible'
}
Thanks!!
This question has an accepted answers - jump to answer
Answers
I found the solution here: https://datatables.net/forums/discussion/29910/prevent-export-of-a-column-with-buttons
The code would be, for example:
Or, even better, put a class or ID to the column that shouldn't be exported: