From 57374fc2b74c7fec5b1e0b123517c463619cc50d Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Thu, 24 Sep 2020 11:55:27 +0300 Subject: [PATCH] Fixed exporting to csv --- src/components/datatable/DataTable.vue | 23 +++++++++++++---------- src/views/datatable/DataTableCrudDemo.vue | 8 ++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/components/datatable/DataTable.vue b/src/components/datatable/DataTable.vue index bf6221c8b..c94622e93 100755 --- a/src/components/datatable/DataTable.vue +++ b/src/components/datatable/DataTable.vue @@ -435,7 +435,6 @@ export default { let columnOrder = []; this.columns.forEach(col => columnOrder.push(col.props?.columnKey||col.props?.field)); this.d_columnOrder = columnOrder; - console.log() } }, beforeUnmount() { @@ -935,14 +934,17 @@ export default { } //headers + let headerInitiated = false; for (let i = 0; i < this.columns.length; i++) { let column = this.columns[i]; + if (column.props?.exportable !== false && column.props?.field) { - csv += '"' + (column.props?.header || column.props?.field) + '"'; - - if (i < (this.columns.length - 1)) { + if (headerInitiated) csv += this.csvSeparator; - } + else + headerInitiated = true; + + csv += '"' + (column.props?.header || column.props?.field) + '"'; } } @@ -950,9 +952,15 @@ export default { if (data) { data.forEach(record => { csv += '\n'; + let rowInitiated = false; for (let i = 0; i < this.columns.length; i++) { let column = this.columns[i]; if (column.props?.exportable !== false && column.props?.field) { + if (rowInitiated) + csv += this.csvSeparator; + else + rowInitiated = true; + let cellData = ObjectUtils.resolveFieldData(record, column.props?.field); if (cellData != null) { @@ -968,12 +976,7 @@ export default { else cellData = ''; - csv += '"' + cellData + '"'; - - if (i < (this.columns.length - 1)) { - csv += this.csvSeparator; - } } } }); diff --git a/src/views/datatable/DataTableCrudDemo.vue b/src/views/datatable/DataTableCrudDemo.vue index 94a83e829..52da239a9 100755 --- a/src/views/datatable/DataTableCrudDemo.vue +++ b/src/views/datatable/DataTableCrudDemo.vue @@ -35,7 +35,7 @@ - + @@ -59,7 +59,7 @@ {{slotProps.data.inventoryStatus}} - +