Hi all!
I'm revisiting a topic from this closed thread, which discussed the need for a feature that allows exporting table data as displayed to the user, with all mappers, filters, etc., applied. The closure of the thread might be due to version discrepancies in the table component (@victoria?), but the need for this feature persists.
In a nutshell, we're looking for a straightforward method to download table data exactly as it appears to the user. I assumed the following code would suffice, as Displayed implies what the user sees, not the underlying data:
const data = await newTable.getDisplayedData();
utils.exportData(data, 'filename', 'csv');
However, this doesn't seem to work as expected. I'm unclear about its function, especially in contrast to this existing method:
await newTable.exportData({fileName: 'test', fileType: 'csv' })
The latter method seems to apply mappings to the headers, which is counterintuitive.
For those who can access an old, legacy table, there's a workaround using a function by @Van:
function formatTablesAsSeen(table) {
var inputData = table.displayedData; // source of data
var inputDataLength = inputData.length;
var headerValuesNew = table.columnHeaderNames; // new header values as objects
var headerKeys = Object.keys(table.columnHeaderNames);
var headerValues = Object.values(table.columns); // current header values as array
var newHeaders = headerValues.map((val) =>
headerKeys.includes(val) ? headerValuesNew[val] : val
);
var headerKeysLength = newHeaders.length;
var outputData = [];
var mappedColumnKeys =
table.columnMappers == undefined ? [] : Object.keys(table.columnMappers);
for (
var inputDataIndex = 0;
inputDataIndex < inputDataLength;
inputDataIndex++
) {
var outputObj = {};
for (
var headerKeysIndex = 0;
headerKeysIndex < headerKeysLength;
headerKeysIndex++
) {
if (table.columnVisibility[headerValues[headerKeysIndex]]) {
if (mappedColumnKeys.includes(headerValues[headerKeysIndex])) {
//outputObj[newHeaders[headerKeysIndex]] = table.columnMappers[headerValues[headerKeysIndex]][inputDataIndex]
var displayedIndex = table.displayedDataIndices[inputDataIndex];
outputObj[newHeaders[headerKeysIndex]] =
table.columnMappers[headerValues[headerKeysIndex]][displayedIndex];
} else {
outputObj[newHeaders[headerKeysIndex]] =
inputData[inputDataIndex][headerValues[headerKeysIndex]];
}
}
}
outputData.push(outputObj);
}
return outputData;
}
@Kabirdas, @victoria, I'm eager to move away from the legacy table, but this feature gap is a significant hurdle. Is there any update on this being addressed in the roadmap? Do you or anyone internally see the value in this feature? Will the new table eventually match the old in this capability?
@alex-w This was solved previously, and I appreciate your backwards compatibility disposition (but we still, effectively, have the same problem... 4. years. later. )
Here's to hoping for innovative table features in 2024!
PS: I understand there might be complexities in implementing this feature without impacting performance. A shoutout to the devs – maybe a Red Bull will give you wings to tackle this challenge! (no disrespect, I'm a dev, and this would scare me too)
I'm available for any clarifications or further discussion.