Export to csv with commas and new lines


I have to export a csv from my grid. Right now I have it working fine with the delimiter being “,”, Please note that the API says single characters only but this does work if you escape it correctly…DHTMLX 2.1!

var str = “”" + grid.serializeToCSV() + “”";
str = str.replace(/\n/g,’"\n"’);

This allows me to get my string in the form: “abc,def”,“abc”,“abc”\n"abc,def" and so on

but I need to allow new lines in my cells. Basically I need a way of enclosing all cell contents into double quotes then using the regular csv function with a comma as my delimiter. Is there a way or can a developer guide me to automatically put cell contents into quotes as well as replacing all existing quotes with “”. I am exporting it to a csv file and Excel allows “” to mean " and “…,…” to mean …,… within a cell

Also note that my exporting is done by sending the csv to a rails server then sending it back as a text/csv octet stream

Add the next line to grid’s init

grid.csvParser = grid.csvExtParser;

After that you can use “,” as separator, quotes will be added automatically. Also it will work correctly with new lines