Skip to content

Instantly share code, notes, and snippets.

@andreisfedotov
Created June 13, 2018 00:48
Show Gist options
  • Save andreisfedotov/1c152e02f0f0b47b08ef9d6b24a4e101 to your computer and use it in GitHub Desktop.
Save andreisfedotov/1c152e02f0f0b47b08ef9d6b24a4e101 to your computer and use it in GitHub Desktop.
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