AnsweredAssumed Answered

Export to CSV file from layer

Question asked by mallareddy2271 on Dec 4, 2018
Latest reply on Dec 4, 2018 by rscheitlin

Below code works in chrome, but it getting syntax error in IE 11 because of expression =>

i used the => expression to filter data,

Any suggestions

Thanks

 

 

function customExportCSV(evt) {

var data = propertylayer._graphicsVal;
var csv = convertArrayOfObjectsToCSV({
data: data
});
if (!csv.match(/^data:text\/csv/i)) {
csv = 'data:text/csv;charset=utf-8,' + csv;
}
//var blob = new Blob([csv], { type: "text/csv" });
//if (navigator.msSaveBlob) { // IE 10+
// //var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
// //navigator.msSaveBlob(blob, "Exportdata.csv");
// navigator.msSaveBlob(blob, "csvname.csv")
//}
var encodedUri = encodeURI(csv);
var link = document.createElement('a');
link.setAttribute('href', encodedUri);
link.setAttribute('download', "Exportdata.csv");
link.click();



}
function convertArrayOfObjectsToCSV(value) {

var result, ctr, keys, columnDelimiter, lineDelimiter, data;
data = Array.from(new Set(value.data)).filter(d => d).map(d => d.attributes) || null;
if (!data || !data.length) {
return null;
}

columnDelimiter = value.columnDelimiter || ',';
lineDelimiter = value.lineDelimiter || '\n';
keys = Object.keys(data[1]);
result = '';
result += keys.join(columnDelimiter);
result += lineDelimiter;
data.forEach(function (item) {
ctr = 0;
keys.forEach(function (key) {
if (ctr > 0)
result += columnDelimiter;
result += item[key];
ctr++;
});
result += lineDelimiter;
});

return result;
}

Outcomes