Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Allow IE11 & Edge to export CSV #1282

Merged
merged 1 commit into from
Jan 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ export default function maExportToCsvButton ($stateParams, Papa, notification, A
var fakeLink = document.createElement('a');
document.body.appendChild(fakeLink);

fakeLink.setAttribute('href', 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(csv));
fakeLink.setAttribute('download', scope.entity.name() + '.csv');
fakeLink.click();
const blobName = `${scope.entity.name()}.csv`;

if (window.navigator && window.navigator.msSaveOrOpenBlob) { // Manage IE11+ & Edge
var blob = new Blob([csv], { type: 'text/csv' });
window.navigator.msSaveOrOpenBlob(blob, blobName);
} else {
fakeLink.setAttribute('href', 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(csv));
fakeLink.setAttribute('download', blobName);
fakeLink.click();
}
}, function (error) {
notification.log(error.message, {addnCls: 'humane-flatty-error'});
});
Expand Down