DataTables Button CSV weird characters on first column title

DataTables Button CSV weird characters on first column title

laureanoarcaniolaureanoarcanio Posts: 3Questions: 1Answers: 0

Hi all, I'm having this issue when exporting to CSV using the buttons plugin, the first column has some weird characters before the Title. Please refer to the screenshot:

http://collabshot.com/show/5hlD8k

I'm currently using nightly build from (today).

Any help will be appreciated.

Thanks!

Answers

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    That's the UTF8 BOM. There isn't currently a way to disable that using a configuration option.

    What spreadsheet viewer are you using? I'm surprised there are any around that can't handle the BOM.

    Allan

  • laureanoarcaniolaureanoarcanio Posts: 3Questions: 1Answers: 0

    HI thanks,

    I'm on a OSX, I see that in Numbers and also in a plain text editor like TextEdit and Sublime.

    Any pointers ?

    Thanks

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    Odd! I don't see it at all in Sublime. I don't have numbers (I'll purchase that soon to test this).

    What browser were you using to create the file?

    Allan

  • laureanoarcaniolaureanoarcanio Posts: 3Questions: 1Answers: 0

    I tried Chrome and FF and see the same issue. Not sure what to do next :(

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    I've just tried downloading a CSV file from this example and then opening it in Numbers 3.6.1 (2566). It appears to open without issue and no BOM in the first cell.

    Allan

  • MrLawlietMrLawliet Posts: 1Questions: 0Answers: 0

    I figured out the solution to those looking for it, you have to not use the minified version and instead get the full from here: https://cdn.datatables.net/buttons/1.1.2/js/buttons.html5.js

    and change the +charset on line 607 to +'UTF-8-BOM' instead so that the section from 606 to 609 looks like this:

        _saveAs(
            new Blob( [output], {type: 'text/csv'+'UTF-8-BOM'} ),
            _filename( config )
        );
    

    That prevents those initial starting chars from appearing for CSV without breaking it for the other buttons if you try to change the charsets earlier in the code.

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    Interesting - thanks for posting this. I'll look into it further.

    Allan

  • marcelvmarcelv Posts: 27Questions: 6Answers: 0

    I had the same issue, thanks for the solution @MrLawliet

  • tfriesttfriest Posts: 1Questions: 0Answers: 0

    That fix isn't really correct.

    My browser (firefox on CentOS 6.6) was trying to use charset = ';charset=UTF-8'
    but when I changed it to use ';charset=UTF-8-BOM', that didn't help.

    removing charset from the line did fix it.

    _saveAs(
    new Blob( [output], {type: 'text/csv'} ),
    _filename( config )
    );

    I guess your fix 'works' because it doesn't actually say ';charset=xxx', and the type of 'text/csvUTF-8-BOM' doesn't confuse the browser...

    It was working prior to 1.1.2 (I don't remember what version I had before).
    I'm using the bootstrap themes too, but that probably doesn't matter.

This discussion has been closed.