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

Exception on IE11 #73

Open
bennne opened this issue Oct 23, 2018 · 3 comments
Open

Exception on IE11 #73

bennne opened this issue Oct 23, 2018 · 3 comments

Comments

@bennne
Copy link

bennne commented Oct 23, 2018

The CSV Export works good (0.2.9) with most browsers. Unfortunaltey we have some devices with IE11 where I get this exception:
2018-10-23 13_29_37-etmc portal - internet explorer

@connybruhn
Copy link

I had the same issue and found a solution.
You have to use the parameter filename twice: within options and as a separate property:

<angular2csv #csvClick [data]="csvData" [filename]="filename" [options]="options"> </angular2csv>

const options: Options = {
    filename: 'filename',
    fieldSeparator: ';',
    quoteStrings: '"',
    decimalseparator: ',',
    showLabels: false,
    showTitle: false,
    title: '',
    useBom: true,
    headers: headersArray,
    keys: keysArray,
    removeNewLines: false
  };

How did I found the solution? I grepped the angular2-csv sourcecode for replace calls and found this:


        if (navigator.msSaveBlob) {
            let /** @type {?} */ filename = this.options.filename.replace(/ /g, '_') + '.csv';
            navigator.msSaveBlob(blob, filename);
        }
        else {
            let /** @type {?} */ uri = 'data:attachment/csv;charset=utf-8,' + encodeURI(this.csv);

            let /** @type {?} */ link = document.createElement('a');
            link.href = URL.createObjectURL(blob);
            link.setAttribute('visibility', 'hidden');
            link.download = this.filename.replace(/ /g, '_') + '.csv';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }

As you can see, if you are a Microsoft browser (browser with msSaveBlob method), filename property is taken by options.
Else filename property is taken as own property.

I my opinion it's a bug, and I'm wondering that I didn't found anything about it. It took some time to find it.

@bennne
Copy link
Author

bennne commented Feb 7, 2019

@connybruhn Thanks! Works great!

@gooza
Copy link

gooza commented Jun 14, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants