From cd26c1ba0cbd09eb48508f2a9daaa823bb39c16a Mon Sep 17 00:00:00 2001 From: Brajesh Kumar Date: Tue, 17 Oct 2023 19:59:14 +0530 Subject: [PATCH] #1918 - corrected the mapping of column and data --- .../entity-list/entity-list.component.ts | 19 ++++---------- .../download-service/download.service.ts | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/app/core/entity-list/entity-list/entity-list.component.ts b/src/app/core/entity-list/entity-list/entity-list.component.ts index 490394502d..d95b2e8b5f 100644 --- a/src/app/core/entity-list/entity-list/entity-list.component.ts +++ b/src/app/core/entity-list/entity-list/entity-list.component.ts @@ -111,8 +111,6 @@ export class EntityListComponent filterObj: DataFilter; filterString = ""; - allData = []; - entitySchema = []; exportEntities = []; get selectedColumnGroupIndex(): number { @@ -305,28 +303,21 @@ export class EntityListComponent } exportFile() { - this.entitySchema = [this.entityConstructor.schema]; + const entitySchema = [this.entityConstructor.schema]; const columnLabel = {}; - this.entitySchema[0].forEach((value: { value: string, label: string }, key: string) => { - if (value.label) { - columnLabel[key] = value.label; - } + entitySchema[0].forEach((value: { value: string, label: string }, key: string) => { + if (value.label) columnLabel[key] = value.label; }); const allData = this.allEntities.map(transformToReadableFormat); this.exportEntities = allData.map((item) => { - const newItem = []; for (const key in item) { - if (columnLabel.hasOwnProperty(key)) { - newItem.push(item[key]) - } + if (!columnLabel.hasOwnProperty(key)) delete item[key]; } - - return newItem; + return item; }); this.exportEntities.push(columnLabel); - } } diff --git a/src/app/core/export/download-service/download.service.ts b/src/app/core/export/download-service/download.service.ts index ad9d247d4b..3757c01336 100644 --- a/src/app/core/export/download-service/download.service.ts +++ b/src/app/core/export/download-service/download.service.ts @@ -102,19 +102,24 @@ export class DownloadService { newline: DownloadService.SEPARATOR_ROW, columns: [...keys], }); - } - - const columnNames = data.pop() - const columnHeader = []; - for (const key in columnNames) { - if (Object.hasOwnProperty.call(columnNames, key)) { - columnHeader.push(columnNames[key]); - } } + + const columnNames = data.pop(); + const columnKeys = Object.keys(columnNames); + const columnLabels:string[] = Object.values(columnNames); + const orderedData = []; + + data.forEach((item) => { + const orderedItem = []; + columnKeys.forEach((key) => { + orderedItem.push(item[key]); + }); + orderedData.push(orderedItem); + }); return this.papa.unparse({ - fields: columnHeader, - data: data + fields: columnLabels, + data: orderedData }); } }