Primeng: CSV export fails with comma values

Created on 6 Apr 2017  路  1Comment  路  Source: primefaces/primeng

I'm submitting a ...

[x ] bug report

Current behavior

If column data includes commas, when exported to csv the data after the comma is moved to the next column, thereby throwing off the formatting of the sheet

Expected behavior
commas should be escaped inside column data so that all the data for the cell stays under its proper column header

Minimal reproduction of the problem with instructions
use a comma inside cell data eg "other , test" then export the table to csv

  • Angular version: 2.4

  • PrimeNG version: 2.0.4

defect

Most helpful comment

This has been an issue for a while, shouldn't be too hard to fix on their end. I think just escaping the string types should work.

In primeng/datatable/datatable.js, line 1452:

//body        
this.value.forEach(function (record, i) {
    csv += '\n';
    for (var i_1 = 0; i_1 < _this.columns.length; i_1++) {
        if (_this.columns[i_1].field) {
            if ( typeof _this.resolveFieldData(record, _this.columns[i_1].field) === 'string' )
              csv += ("\"" + _this.resolveFieldData(record, _this.columns[i_1].field) + "\"");
            else
              csv += _this.resolveFieldData(record, _this.columns[i_1].field);
            if (i_1 < (_this.columns.length - 1)) {
                csv += _this.csvSeparator;
            }
        }
    }
});

>All comments

This has been an issue for a while, shouldn't be too hard to fix on their end. I think just escaping the string types should work.

In primeng/datatable/datatable.js, line 1452:

//body        
this.value.forEach(function (record, i) {
    csv += '\n';
    for (var i_1 = 0; i_1 < _this.columns.length; i_1++) {
        if (_this.columns[i_1].field) {
            if ( typeof _this.resolveFieldData(record, _this.columns[i_1].field) === 'string' )
              csv += ("\"" + _this.resolveFieldData(record, _this.columns[i_1].field) + "\"");
            else
              csv += _this.resolveFieldData(record, _this.columns[i_1].field);
            if (i_1 < (_this.columns.length - 1)) {
                csv += _this.csvSeparator;
            }
        }
    }
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

KannanMuruganmony picture KannanMuruganmony  路  3Comments

Helayxa picture Helayxa  路  3Comments

lilling picture lilling  路  3Comments

pchristou picture pchristou  路  3Comments

philly-vanilly picture philly-vanilly  路  3Comments