[ Bug fixed ] : [ Table ] When column name is changes, particular column data becomes empty when downloaded (#5479)

* bug fixed :when column name is changes, particular column data becomes empty when downloaded

* bug fixed

* refactored the code to improve readability by changing reduce function to map function
This commit is contained in:
Manish Kushare 2023-02-07 12:59:33 +05:30 committed by GitHub
parent a63a4639bf
commit 94f68039cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -195,14 +195,22 @@ export function Table({
}
function getExportFileBlob({ columns, fileType, fileName }) {
let headers = columns.map((col) => String(col.exportValue));
let headers = columns.map((column) => {
return { exportValue: String(column.exportValue), key: column.key ? String(column.key) : column.key };
});
const data = globalFilteredRows.map((row) => {
return headers.reduce((acc, header) => {
acc[header.toUpperCase()] = row.original[header];
return acc;
return headers.reduce((accumulator, header) => {
let value = undefined;
if (header.key && header.key !== header.exportValue) {
value = row.original[header.key];
} else {
value = row.original[header.exportValue];
}
accumulator[header.exportValue.toUpperCase()] = value;
return accumulator;
}, {});
});
headers = headers.map((header) => header.toUpperCase());
headers = headers.map((header) => header.exportValue.toUpperCase());
if (fileType === 'csv') {
const csvString = Papa.unparse({ fields: headers, data });
return new Blob([csvString], { type: 'text/csv' });
@ -338,7 +346,6 @@ export function Table({
darkMode,
] // Hack: need to fix
);
const data = useMemo(
() => tableData,
[

View file

@ -66,6 +66,7 @@ export default function generateColumnsData({
cellBackgroundColor: column.cellBackgroundColor,
columnType,
isEditable: column.isEditable,
key: column.key,
Cell: function (cell) {
const rowChangeSet = changeSet ? changeSet[cell.row.index] : null;
let cellValue = rowChangeSet ? rowChangeSet[column.name] || cell.value : cell.value;