i am downloading the lightning data in CSV file as per the below screenshot enter image description here

Now the issue is whenever i am trying to expand the Name column,the data is getting restricted to the name column only.Like the industry field value 'engineering','Consulting' is not getting shifted to the industry column. The reason being the data is concatenated and then coming in CSV as per the below code.

for(var key in dat.getReturnValue()){
  csvContent +=dat.getReturnValue()[key].Name+" "+dat.getReturnValue()[key].Industry+"\r\n" ;

            var encodedUri = encodeURI(csvContent);
  • where exactly are you stuck? what problem are you facing? any errors? what is the current behavior, vs the expected one? – glls Sep 23 '19 at 13:28
  • actually the values in rows needs to be displayed exactly in CSV file after download,so the format is just like i have asked . in my code only name is coming ,don't know how to fetch industry and phone field. – vineet Sep 23 '19 at 13:31
  • @glls :- have edited the js controller code for table header.But how to align the records under the heading . – vineet Sep 23 '19 at 13:37

In for loop you can make changes as below code:

for (var key in response.getReturnValue()) {
    rows.push(response.getReturnValue()[key].Name + "," + response.getReturnValue()[key].City + "," + response.getReturnValue()[key].Phone);
const rowsHeader = [
    ["Name", "City", "Phone"]


 let str = "data:text/csv;charset=utf-8,";
    rowsHeader.forEach(function(header) {
    // Here it will get all the values with comma separated.
        str += header + "\r\n";

Hope it will solve your question!

| improve this answer | |
  • i think almost i got it but some garbage values are coming. let me try it once more. – vineet Sep 23 '19 at 13:53
  • Can you post what garbage values you are getting in CSV file? – Chetan Nandre Sep 23 '19 at 13:57
  • the third column 'undefined' is coming on its own. i have used ur code for the first two columns only .Dont know from where the third column undefined is coming. – vineet Sep 23 '19 at 14:05
  • can you edit your post with latest code? – Chetan Nandre Sep 23 '19 at 14:13
  • is it possible to modify the code in such a way ,that the record section should also get movable.??? – vineet Sep 23 '19 at 14:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.