Fixed #413 - DataTable: Exporting an empty DataTable throws TypeError

pull/426/head
cagataycivici 2020-08-04 15:46:23 +03:00
parent aac75d9084
commit ab589686f1
1 changed files with 27 additions and 25 deletions

View File

@ -953,35 +953,37 @@ export default {
} }
//body //body
data.forEach(record => { if (data) {
csv += '\n'; data.forEach(record => {
for (let i = 0; i < this.columns.length; i++) { csv += '\n';
let column = this.columns[i]; for (let i = 0; i < this.columns.length; i++) {
if (column.exportable !== false && column.field) { let column = this.columns[i];
let cellData = ObjectUtils.resolveFieldData(record, column.field); if (column.exportable !== false && column.field) {
let cellData = ObjectUtils.resolveFieldData(record, column.field);
if (cellData != null) {
if (this.exportFunction) { if (cellData != null) {
cellData = this.exportFunction({ if (this.exportFunction) {
data: cellData, cellData = this.exportFunction({
field: column.field data: cellData,
}); field: column.field
});
}
else
cellData = String(cellData).replace(/"/g, '""');
} }
else else
cellData = String(cellData).replace(/"/g, '""'); cellData = '';
}
else
cellData = ''; csv += '"' + cellData + '"';
if (i < (this.columns.length - 1)) {
csv += '"' + cellData + '"'; csv += this.csvSeparator;
}
if (i < (this.columns.length - 1)) {
csv += this.csvSeparator;
} }
} }
} });
}); }
let blob = new Blob([csv], { let blob = new Blob([csv], {
type: 'text/csv;charset=utf-8;' type: 'text/csv;charset=utf-8;'