Last active
June 24, 2020 21:35
-
-
Save toddsiegel/d41207378313c487d590503edc91fd6f to your computer and use it in GitHub Desktop.
Client-side CSV Download
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
const exportRows = [ | |
["Name", "Email"], | |
["Foo Bar", "foo@bar.com"] | |
]; | |
const csvContent = "data:text/csv;charset=utf-8," + exportRows.map((e) => e.join(",")).join("\n"); | |
const encodedUri = encodeURI(csvContent); | |
const link = document.createElement("a"); | |
link.setAttribute("href", encodedUri); | |
link.setAttribute("download", "export.csv"); // https://caniuse.com/#feat=download | |
document.body.appendChild(link); // FF aparently needs this. | |
link.click(); | |
document.body.removeChild(link); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment