Prevent export of a column with Buttons
Prevent export of a column with Buttons
I am using Buttons to do a DataTables export. I'm trying to export the visible columns in the table, but also want to prevent the first column from exporting regardless of the column visibility options set (the first column has an Edit button in it that messes up the export).
In all the examples I could find, they referenced TableTools and mColumn which are retired. And I couldn't seem to find a combination of hiding a specific column on export while retaining visibility of the remaining columns.
Anyone know what I'm missing? Here is what I have so far (just using Copy in this example though I'm also using Excel and PDF):
buttons: [
{
extend: 'copy',
exportOptions: {
columns: [ ':visible' ]
}
},
'colvis'
],
Answers
same here :/ does anyone have a solution for this? (DataTables 1.10.9)
Poke, im trying to do this too, I tried columns: [ ':visible', '-1' ] as I was hoping that would hide the first but no dice...
Maybe set the column to hidden then export and set it back to visible?
There is an example of how to select which columns to export.
In the case of hiding just the first column you could try
:not(:first-child)
.Allan
@allan
What if I need to hide the last two columns only?
jQuery allows you do combine selectors in the
:not()
selector using the standard comma separator. See the jQuery selector documentation for full details of the selectors available.Allan