Unexpected csvHtml5 export behavior

Unexpected csvHtml5 export behavior

benjaminbaldonibenjaminbaldoni Posts: 11Questions: 3Answers: 1

Hello, I'm using the buttons extension (specifically the csvHtml5 feature), and I believe there is an issue when exporting tables with commas in cell values. The resulting CSV will split cells into different values because of the commas. I believe that the previous flash plugin would automatically trim the commas in order to avoid that unexpected behaviour.

Export this example and see how the Salary is splitted in two (or three) cells: https://datatables.net/extensions/buttons/examples/html5/simple.html

How can I avoid that? I tried to define a cellRender function (or something like that) in the button settings to remove the commas before exporting, but I failed.

Thank's for reading.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,704Questions: 1Answers: 10,502 Site admin
    Answer ✓

    The current release of Buttons has an error in this button type whereby it should, but doesn't, specify a field boundary. This can be corrected in the current release by using the fieldBoundary option:

    {
      extend: 'csvHtml5',
      fieldBoundary: '"'
    }
    

    That, and the fact that if there is a field boundary it wouldn't be escaped, was addressed in this commit and will be included in the next release.

    Allan

  • benjaminbaldonibenjaminbaldoni Posts: 11Questions: 3Answers: 1

    Thanks! It's working fine now.

    Would you mind telling me how can I format cells (and column header, if possible) before exporting?

    Something like fnCellRender function in the flash export will do.

  • allanallan Posts: 63,704Questions: 1Answers: 10,502 Site admin

    You need to use the columns.render option as a function and the buttons.exportData() method's ability specify what orthogonal data it should request (through the orthogonal property.

    Allan

This discussion has been closed.