Skip to content

Commit

Permalink
Allow IE11 & Edge to export CSV
Browse files Browse the repository at this point in the history
Fix #1116
  • Loading branch information
Kmaschta committed Dec 22, 2016
1 parent 80d6537 commit 70c0469
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 70c0469

Please sign in to comment.