From c880e9012d8db5ba0f34fa01112862f4a3047d8a Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 12 Apr 2022 17:19:00 +0530 Subject: [PATCH] fix: csv download with filter , sort and fields option re #1660 Signed-off-by: Pranav C --- .../spreadsheet/components/moreActions.vue | 11 ++++++- .../project/spreadsheet/public/xcTable.vue | 2 +- .../lib/dataMapper/lib/sql/BaseModelSqlv2.ts | 2 +- .../api/publicApis/publicDataExportApis.ts | 30 +++++++++++++------ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue b/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue index fe5ad1faff..630f94eb7c 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue @@ -240,7 +240,16 @@ export default { res = await this.$api.public.csvExport(this.publicViewId, ExportTypes.CSV, { responseType: 'blob', query: { - offset + fields: this.queryParams && this.queryParams.fieldsOrder && this.queryParams.fieldsOrder.filter(c => this.queryParams.showFields[c]), + offset, + sortArrJson: JSON.stringify(this.reqPayload && this.reqPayload.sorts && this.reqPayload.sorts.map(({ + fk_column_id, + direction + }) => ({ + direction, + fk_column_id + }))), + filterArrJson: JSON.stringify(this.reqPayload && this.reqPayload.filters) }, headers: { 'xc-password': this.reqPayload && this.reqPayload.password diff --git a/packages/nc-gui/components/project/spreadsheet/public/xcTable.vue b/packages/nc-gui/components/project/spreadsheet/public/xcTable.vue index b7a5020302..fdbdd2ed5b 100644 --- a/packages/nc-gui/components/project/spreadsheet/public/xcTable.vue +++ b/packages/nc-gui/components/project/spreadsheet/public/xcTable.vue @@ -49,7 +49,7 @@ c.title), + fields: model.columns + .sort((c1, c2) => + Array.isArray(fields) + ? fields.indexOf(c1.title as any) - fields.indexOf(c2.title as any) + : 0 + ) + .filter( + c => + !fields || !Array.isArray(fields) || fields.includes(c.title as any) + ) + .map(c => c.title), data: csvRows }, {