Skip to content

Commit

Permalink
fix row end with a superfluous comma when export csv
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Jan 19, 2016
1 parent f39ccfc commit 078d91d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/csv_export_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ if(typeof window !== 'undefined'){
function toString(data, keys) {
var dataString = "";
if (data.length === 0) return dataString;

dataString += keys.join(',') + '\n'

data.map(function(row) {
keys.map(function(col) {
var cell = row[col] ? ('"'+row[col]+'"') : "";
dataString += cell + ',';
keys.map(function(col, i) {
let cell = typeof row[col] !== 'undefined' ? ('"'+row[col]+'"') : "";
dataString += cell;
if (i+1 < keys.length)
dataString += ',';
});

dataString += '\n';
Expand All @@ -26,7 +28,7 @@ var exportCSV = function(data, keys, filename) {
if (typeof window !== 'undefined') {
saveAs( new Blob([dataString], {type: "text/plain;charset=utf-8"}), filename || 'spreadsheet.csv' );
}

};

export default exportCSV;

0 comments on commit 078d91d

Please sign in to comment.