Export columns are not as expected
Export columns are not as expected
Datatables v1.12.1
Test Case: https://jsfiddle.net/Cyberjetx/hgvtqxux/50/
Description of problem: When setting the exported columns with the excel class to limit export you will get all of the columns even though we have omited cols 0 & 5 from export. If you filter column visibility in any way that hides omited columns, then, the column(s) hidden will be excluded from export.
"columnDefs": [
{ targets: [0, 1], className: 'noVis' /* No Hiding */ },
{ targets: [1, 2, 3, 4], className: 'excel' /* export all but name & salary */ }
]
...
exportOptions: {
columns: [':visible(.excel)'],
}
What have I missed in my setup?
Answers
I don't thing the
:visible
selector can take parameters can it? This is the jQuery docs on it and there is no indication of that.Allan
It works but oddly.
'.excel:visible'
works as a jQuery selector in the console but breaks the export.I desire to export only visible .excel columns.
I was thinking that I could use the
.on('column-visibility.dt'
to modify the class to something I can toggle eg excelOff or something. Or is there a better datatables centric way to do it?I tried to make class changes when the columns were toggled.
http://jsfiddle.net/Cyberjetx/hgvtqxux/53/
This is a fail too. I believe is is because I am modding the dom outside datatables' purview.
Any ideas?
UPDATE:
columns: [':visible.excel'],
is working as expected. I also tried.filter()
but that also broke the export.I hope this helps the lurkers.
Fixed version: http://jsfiddle.net/Cyberjetx/hgvtqxux/54/
I wonder if this is valuable as an export option switch, maybe
IncludeHidden
true by default. It could be too much of a one off though.