mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
[ 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:
parent
a63a4639bf
commit
94f68039cb
2 changed files with 14 additions and 6 deletions
|
|
@ -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,
|
||||
[
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue