Exclude column by it's title while exporting data.
Exclude column by it's title while exporting data.

Hi All,
I am a bit new to datatables, I wanted to exclude a column while exporting which title is Action.
Basically I have to exclude two types of columns the one which have the class col-dt-hidden and the other which title is Action.
I wanted to do something like exportOptions: {columns: [':not(.col-dt-hidden, Action):visible']},
The Action is title of the column.
Please help me!, I have google for many hours but didn't get a solution.
This question has accepted answers - jump to:
Answers
The Column Selector Example links to the
column-selector
docs which document all the options you have for select columns. You can use the Function Selector like this:http://live.datatables.net/fegomebe/1/edit
The example is removing the
Name
andPosition
columns but it also specifies column 0 (Name). Did this to show using a function with multiple column-selectors. All but Position are exported.Kevin
Thanks @kthorngren This works and helped me alot...
Hi @kthorngren,
the above example is work for me but it is including the column in export which is hidden by colvis.
Can i excluide those columns which is hidden by colvis.
Pls help.
Inside the
exportOptions
function, you can add an additional test for the column's visibility withcolumn().visible()
. If that doesn't help, please can you update Kevin's last test case to demonstrate the issue,Colin
Hi @Colin, sorry for the late reply,
please check here my code is http://live.datatables.net/runaxajo/1/edit
The issue is, i am using the colvis to show/hide column so here i want to not include the column in export which is hidden.
but using the above code is including the hidden column also.
Yep, I get that, did you try my suggestion above? That example is the same as Kevin's - could you update it please so that it's showing what you have,
Colin
Please check this
http://live.datatables.net/zokonero/2/edit
This is how exactly my code is...
Here's the updated version - I made
age
hidden - I used method described in my earlier post,Colin
Thanks @colin for your help.. this is working if the table is initialize on the same file.
But the main problem is I don't have the table object in the js file where I am trying to achieve this.
The table initialization codes are in different files(around 100 files) and I want to do this for all of them without making changes on all the file where the table has initialized.
How can I do that? Please help me on that.
http://live.datatables.net/zokonero/6/edit
Instead of
table
in my example, you can use$('table').DataTable()
, instead - http://live.datatables.net/zokonero/7/editColin
Thanks @colin This is working... but I got one more doubt.
is there a way i can get the table id?
I mean it will be a better to use the table id.
You could use the
node
, the last parameter to that function. That's the node of the column. You can use jQuery to then get the ID of the parent table.Colin
See if this works for what you want:
var tableId = $(node).closest('table').attr('id');
For example:
http://live.datatables.net/zokonero/9/edit
Kevin
Thanks @kevin, @colin
var tableId = $(node).closest('table').attr('id');
I am getting tableId
undefined
if the particular node is hidden.But I can do some workaround with above example.
Thanks.
.