fooplugins / FooTable

jQuery plugin to make HTML tables responsive
https://fooplugins.com/plugins/footable-jquery/
Other
2.13k stars 637 forks source link

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

Open vcidst opened 4 years ago

vcidst commented 4 years ago

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.