Last active
February 10, 2019 19:13
-
-
Save bilashcse/acac3710d1495d8bc493f1bdbc52cbdb to your computer and use it in GitHub Desktop.
Initial zero supported Mobile/ Phone Numbers CSV download front-end hack with Unicode supports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let csvContent = "data:application/vnd.ms-excel;charset=utf-8,\uFEFF"; | |
let csvArray = [ | |
[ | |
"Id", | |
"Name", | |
"Phone" | |
] | |
]; | |
usersArray.forEach(user => { | |
csvArray.push([ | |
user.id, | |
user.name, | |
"=\"" + user.phone + "\"" | |
]); | |
}); | |
csvArray.forEach(infoArray => { | |
let dataString = infoArray.join(","); | |
csvContent = csvContent + dataString + "\n"; | |
}) | |
let encodedUri = encodeURI(csvContent); | |
let link = document.createElement("a"); | |
link.setAttribute("href", encodedUri); | |
link.setAttribute("download", "download-user-info.csv"); | |
document.body.appendChild(link); | |
link.click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment