UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

17 lines (16 loc) 659 B
export const downloadCSV = (csv: string, filename: string = 'export'): void => { const fakeLink = document.createElement('a'); fakeLink.style.display = 'none'; document.body.appendChild(fakeLink); const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' }); // @ts-ignore if (window.navigator && window.navigator.msSaveOrOpenBlob) { // Manage IE11+ & Edge // @ts-ignore window.navigator.msSaveOrOpenBlob(blob, `${filename}.csv`); } else { fakeLink.setAttribute('href', URL.createObjectURL(blob)); fakeLink.setAttribute('download', `${filename}.csv`); fakeLink.click(); } };