FooTable icon indicating copy to clipboard operation
FooTable copied to clipboard

CSV download doesn't work if there is '#' in ToCSV() output

Open vcidst opened this issue 6 years ago • 0 comments

Hello,

If there's a column named # in the output CSV string, the generated CSV file doesn't contain the correct data.

Here's a fiddle with # in column name: https://jsfiddle.net/5qghjf4r/

var csvContent = '" # "," Name "," Code "," Party "," Mobile "," Phone "," Email "," Action "\n"1","John Doe","5809","","","Foo","",""';
var link = window.document.createElement("a");
link.setAttribute("href", "data:text/csv;charset=utf-8,%EF%BB%BF" + encodeURI(csvContent));
link.setAttribute("download", "upload_data.csv");
link.click();

The generated CSV file is empty

Here's a fiddle with # replaced by 1 in column name: https://jsfiddle.net/psogk2f3/

var csvContent = '" 1 "," Name "," Code "," Party "," Mobile "," Phone "," Email "," Action "\n"1","John Doe","5809","","","Foo","",""';
var link = window.document.createElement("a");
link.setAttribute("href", "data:text/csv;charset=utf-8,%EF%BB%BF" + encodeURI(csvContent));
link.setAttribute("download", "upload_data.csv");
link.click();

The generated CSV file contains data as expected.

I'm not sure what is causing this behavior but I just spent nearby two hours splitting my hairs on this issue while working on a FooTable element.

vcidst avatar Jan 01 '20 06:01 vcidst