Export CSV (rendered field)
Export CSV (rendered field)

https://datatables.net/reference/button/csv
If you export a CSV, I'm unsure how to include the text of a rendered column (or the original text) in the export data. For instance assume there is a 'private' column that is converted to an icon via the render() method:
buttons: [ {
extend: 'csv',
customize: function(csv){
// csv does not include the 'private' data (or html icon)
}
} ],
columns: [ {
data: 'private',
render: function(data){ if (data) data='<i class="private-icon"></i>'; return data; }
} ]
The CSV export only includes an empty string, not the original pre-rendered data/text, nor the post-rendered html. Is there a way to have the original data be exported at this stage of the export?
This question has an accepted answers - jump to answer
Answers
Yep, you can use orthogonal data data for that - see an example here.
Colin
@colin that did the trick -- much appreciated as I probably would have spent way too long looking for that.
For clarification to others, this can be accomplished with setting exportOptions on the button (see example below).
Given the above, which shows other fields that are used, the CSV output is displayed as
null
for the name and years data. Is there a simple way of telling the exporter to convert nulls to empty strings?Edit
_It seems the columnDefs would overrides other column definitions. For the time being, I do not want to submit this as an answer while still experimenting.
Note: the tildes below should be converting the text to strikethrough, but the markdown renderer doesn't seem to be allowing for that. Assume it's strikethrough text until fixed. (if you're seeing strikethrough text, it means the markdown renderer has been updated)._
Initial Post
As a follow-up, ~~it seems this can be accomplished by adding a general columndef~~:
~~I'm not sure if they stack, but I guess I'll cross that bridge when I come to it.~~
Yep, you can have
columnDefs
andcolumns
together, but you can merge thecolumnDefs
config into thecolumns
object.Colin