I have a requirement to export data from an Aura component to a CSV. My solution is working until I hit around 3k records at that point the CSV no longer seems to contain all the data. At 6k records, I get a "download failed Network Error" message. And at around 7k, the browser will time out.
Is there a way to implement this to deal with larger data volumes? Up to 10k records or so?
I used a solution I found here and was also mention in another thread on Stack Exchange.
Here is my controller
handleExport: function(component, event, helper){
var contactList = component.get('v.completeResults');
var csv = helper.convertListToCSV(component, contactList);
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
hiddenElement.target = '_self'; //
hiddenElement.download = 'EmailSendList.csv'; // CSV file Name* you can change it.[only name not .csv]
document.body.appendChild(hiddenElement); // Required for FireFox browser
hiddenElement.click(); // using click() js function to download csv file
}
Here is my helper
convertListToCSV: function (component, list) {
var csvStringResult, counter, keys, columnDivider, lineDivider;
var csvHeader = '*** Changes to CSV Will Not be Saved Back To Event App *** ';
// check if "list" parameter is null, then return from function
if (list == null || !list.length) {
return null;
}
// store ,[comma] in columnDivider variabel for sparate CSV values and
// for start next line use '\n' [new line] in lineDivider varaible
columnDivider = ',';
lineDivider = '\n';
// in the keys valirable store fields API Names as a key
// this labels use in CSV file header
keys = ['Delivery_Name', 'InformalSalutation', 'Last_Name', 'Email1', 'Inviter_Name', 'GalileoId', 'Relationship_Type',
'Age', 'BAOffice', 'MarketingRestrictions', 'OptOut', 'PrimaryContact', 'BillingCity', 'BillingState',
'Company', 'BA_Relationship', 'LastModifiedName', 'LastModifiedDate', 'LastModifiedDate', 'contactId'];
csvStringResult = csvHeader + lineDivider;
csvStringResult += keys.join(columnDivider);
csvStringResult += lineDivider;
for(var i=0; i < list.length; i++){
counter = 0;
for(var sTempkey in keys) {
var skey = keys[sTempkey] ;
// add , [comma] after every String value,. [except first]
if(counter > 0){
csvStringResult += columnDivider;
}
csvStringResult += '"'+ list[i][skey]+'"';
counter++;
} // inner for loop close
csvStringResult += lineDivider;
}// outer main for loop close
// return the CSV format String
return csvStringResult;
}