Created
June 13, 2018 00:48
-
-
Save andreisfedotov/1c152e02f0f0b47b08ef9d6b24a4e101 to your computer and use it in GitHub Desktop.
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
public static downloadcsv(data: any, exportFileName: string) { | |
const csvData = this.convertToCSV(data); | |
const blob = new Blob([csvData], { type: 'text/csv;charset=utf-8;' }); | |
if (navigator.msSaveBlob) { // IE 10+ | |
navigator.msSaveBlob(blob, this.createFileName(exportFileName)); | |
} else { | |
const link = document.createElement('a'); | |
if (link.download !== undefined) { // feature detection | |
// Browsers that support HTML5 download attribute | |
const url = URL.createObjectURL(blob); | |
link.setAttribute('href', url); | |
link.setAttribute('download', this.createFileName(exportFileName)); | |
//link.style = "visibility:hidden"; | |
document.body.appendChild(link); | |
link.click(); | |
document.body.removeChild(link); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment