How to use exportOptions modifier columns to export all exept last column?
How to use exportOptions modifier columns to export all exept last column?
laurynas
Posts: 1Questions: 1Answers: 0
So I'm using this new DataTables with dataTables.buttons and I was wondering how do I export all exept the last column.
Could anyone help me out?
$table.dataTable({
buttons:{extend: 'excelHtml5',
className: 'my-button-class',
title: 'myTitle',
text: 'Export',
exportOptions: {
modifier: {
columns: ???
}
}
}
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Pretty sure you just list the columns you want exported.
IE columns:[0,1,2,3]
If you have 5 columns then you would leave 4 off.
Since you can use a jQuery selector you can use
:not(:last-child)
to ignore the last column, or use an array of indexes as Redbaron67 suggests.Allan
can you tell what to do if you want to print specific array of columns which changes on the run.
exportOptions: {
@tsprasanth - As in you want to be able to dynamically modify the
columns
option after initialisation? There is no API for that at the moment. What you could do is use a class name selector and change the class names on the header cells in the table, that would have the same effect.Allan
Hi Allan,
can i have any example to achieve dynamically modify the columns option?
Rafidheen M
Sorry if I wasn't clear enough above. There is no option for that at the moment.
You could use the
columns
option as a function and dynamically calculate which columns you want to include, but that's about it.Allan
Allen,
I tried like this..
exportOptions: {
columns: function () {
return [1,2,3];
}
}
the above code does not works. And it exports all the columns in the grid.
Note : on the above code, instead of
[1,2,3];
i will suppose to call my custom function which will return a list of integer array. But the above code itself is not working.That's not how
columns
works as a function. See the documentation here. Basically it is executed for each column in the table and you need to return true or false to indicate if that column should be included or not (i.e. filter out the ones you don't want).Allan