Skip to content

Commit

Permalink
#1918 - corrected the mapping of column and data
Browse files Browse the repository at this point in the history
  • Loading branch information
Brajesh Kumar authored and Brajesh Kumar committed Oct 17, 2023
1 parent 7efebd8 commit cd26c1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
19 changes: 5 additions & 14 deletions src/app/core/entity-list/entity-list/entity-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ export class EntityListComponent<T extends Entity>
filterObj: DataFilter<T>;
filterString = "";

allData = [];
entitySchema = [];
exportEntities = [];

get selectedColumnGroupIndex(): number {
Expand Down Expand Up @@ -305,28 +303,21 @@ export class EntityListComponent<T extends Entity>
}

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);

}
}
25 changes: 15 additions & 10 deletions src/app/core/export/download-service/download.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}

0 comments on commit cd26c1b

Please sign in to comment.