PROBLEM:
Downloaded CSV file is blank (unparse()
method to conver array/JSON to CSV).
DETAIL:
Papaparse is working fine when parse CSV file to JavaScript array. But when I feed that array data or JSON data to unparse()
method, its not working.
Angular JS method:
$scope.downloadCSV = function(){
var csv = Papa.unparse($scope.final_array);
console.log($scope.final_array);
console.log(csv);
var csvData = new Blob([csv], {type: 'text/csv;charset=utf-8;'});
var csvURL = null;
if (navigator.msSaveBlob) {
csvURL = navigator.msSaveBlob(csvData, 'download.csv');
} else {
csvURL = window.URL.createObjectURL(csvData);
}
var tempLink = document.createElement('a');
tempLink.href = csvURL;
tempLink.setAttribute('download', 'download.csv');
tempLink.click();
}
$scope.final_array
contains data as:
On above code, console.log(csv);
displays blank on the console.
In short: var csv = Papa.unparse($scope.final_array);
is not working.
UPDATE
The posted array help me to generate following table and the button "Save Generated CSV" is not working and the code posted is for the this action button.
tempLink.remove()
at the end of the function to prevent them building up on the page. – Joke