Data Export Questions
Data Export Questions
This example uses a copyHtml5 and a csvHtml5 button: live.datatables.net/tudacode/1/edit
I am struggling to find a solution to the following:
copyHtml5
Is it possible to remove the "DataTables - JS Bin" at the beginning of the copied text (for some reason it says "Exported Data" in my project instead)?
Can we remove all spaces from the copied text?
Is there maybe a way to not add a comma after the last row/copied cell?
csvHtml5
Is it possible to export the data as a .txt file instead of .csv or to rename it before export?
When opening the .csv file in a text editor, all exported cells have quotation marks around them. Is it possible to remove these?
This question has accepted answers - jump to:
Answers
Take a look at this example and the
buttons.exportInfo()
docs it links to. I believe you will want to settitle
to null or""
.Not sure if there are any examples on the forum but the customize function is used to modify the exported contents.
I guess the comma is part of your data? Use the customize function.
See this example for setting the filename.
Try setting the
fieldSeparator
option found in the csvHtml5 options.Kevin
@kthorngren Thank you so much for this! Most of it worked here:
live.datatables.net/vatoruli/1/edit
Still struggling with the following:
No comma after the last copied cell value: Not sure how to use the customize function on the copied text from copyHtml5. Alternatively, I was thinking to add fieldSeparator: ',' to only have commas between copied cell values but this does not seem to work for copyHtml5.
Text file export: Changing the filename for csvHtml5 to Test.txt exports the data as Test.txt.csv - how can I remove .csv from the exported file?
Thanks for the test case.
Looks like the
row
parameter of the body function is the row counter. You can compare the row counter to the number of rows being exported, using something like this:Note the use of the
selector-modifier
of{page: 'current'}
to matchrows: [':visible'],
. This also uses thecount()
API.Good question. I tried a function and it still added
.csv
. @allan or @colin will need to provide input for this issue.See the updated example for both questions:
http://live.datatables.net/padomemo/1/edit
Kevin
@kthorngren Thank you for your help! I added another example based on yours to get no comma after the last copied cell for all rows of filtered results (not just visible rows):
live.datatables.net/molujaye/1/edit
It works quickly on the test case, but when we have 9000+ rows, this takes a very long time to load. Is there another way to get the rows count for filtered results quicker?
I suspect the line
will be inefficient, as this is getting all the rows to just count them. It would be better to use something like:
Could you see if that helps, please,
Colin
@colin Yes this is much faster! Thank you very much!
Do you think there is a way to export the data as a .txt file? No matter what, the export is always in .csv or .txt.csv for csvHtml5.
A CSV is just a text file, so you should set the
fieldSeparator
to' '
(a space) and that would generate a more standard text file.Colin
@colin Adding the fieldSeparator ' ' exports a "Test.txt .csv" file with a space and the .csv remains:
live.datatables.net/lojokemi/1/edit
Ah, yep, you also need to set the extension:
See here: http://live.datatables.net/lojokemi/2/edit
Colin
Please see the full list of options here:
https://datatables.net/reference/button/csvHtml5
Colin
Thank you!