CSV Export header doesn't work
CSV Export header doesn't work
Hi
I'm trying to add a header to my csv file, I found an example here
https://datatables.net/forums/discussion/comment/100228/#Comment_100228
but it looks like it's not working.
My header is a predefined string, but by putting a \n at the end of the string the button is not generated on the screen.
As explained in the example, by putting a \n header in the end of the string the line skips then showing the contents of the file
Here is my code:
var buttons = new $.fn.dataTable.Buttons(table, {"+
"buttons: [{"+
" extend:'csvHtml5',"+
" className: 'bluenavbutton',"+
" text:'<i class=\"glyphicon glyphicon-export font-button glyph-sm\"></i> " + user.getString("csv") + "',"+
" title:'" + reportType + reportRequest.getParameter("period") + "',"+
" titleAttr: '" + user.getString("download_csv") + "',"+
" customize: function (csv) {"+
" return \""+header.toString()+"\" + csv;"+
" }"+
"}]"+
"}).container().appendTo($('#csvNavButton'));
If i don't put the \n at the end of the string the button works fine
This question has an accepted answers - jump to answer
Answers
Can you link to a test case showing the issue please.
Allan
Hi Allan
Thanks for your fast reply.
I have managed to solve the problem by putting an extra "\" before the "\n".
var buttons = new $.fn.dataTable.Buttons(table, {"+
"buttons: [{"+
" extend:'csvHtml5',"+
" className: 'bluenavbutton',"+
" text:'<i class=\"glyphicon glyphicon-export font-button glyph-sm\"></i> CSV',"+
" title:'" + reportType + reportRequest.getParameter("period") + "',"+
" titleAttr: 'CSV',"+
" customize: function (csv) {"+
" return \""+header.toString()+"\\n\" + csv;"+
" }"+
"}]"+
"}).container().appendTo($('#csvNavButton'));
Thanks again !!
Thanks for posting back - good to hear you've got it working!
Allan