From 7c17a4852577c6e6290cd0b1fb4278b8b4584ff7 Mon Sep 17 00:00:00 2001 From: Faran Javed Date: Fri, 17 Oct 2025 17:43:56 +0500 Subject: [PATCH 1/2] [Feat]: #1795 add table download --- .../src/comps/comps/tableComp/tableComp.tsx | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx b/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx index f050997a0..a8d151d1e 100644 --- a/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx @@ -99,12 +99,65 @@ export class TableImplComp extends TableInitComp implements IContainer { } downloadData(fileName: string) { - saveDataAsFile({ - data: (this as any).exposingValues["displayData"], - filename: fileName, - fileType: "csv", - delimiter: this.children.toolbar.children.columnSeparator.getView(), - }); + const allDisplayData = (this as any).exposingValues["displayData"]; + const delimiter = this.children.toolbar.children.columnSeparator.getView(); + + try { + // Build the set of visible column keys as shown to the user (title or dataIndex) + const enableColumnSetting = this.children.toolbar.children.columnSetting.getView(); + const visibleColumnKeys = new Set(); + this.children.columns.getView().forEach((col) => { + const colView = col.getView(); + const isHidden = columnHide({ + hide: colView.hide, + tempHide: colView.tempHide, + enableColumnSetting, + }); + if (!isHidden) { + const headerKey = (colView.title as any) || colView.dataIndex; + if (headerKey) { + visibleColumnKeys.add(String(headerKey)); + } + } + }); + + const pickVisible = (row: any): any => { + const result: any = {}; + // copy only allowed keys + Object.keys(row || {}).forEach((key) => { + if (key !== COLUMN_CHILDREN_KEY && visibleColumnKeys.has(key)) { + result[key] = row[key]; + } + }); + // retain children recursively if present + if (Array.isArray(row?.[COLUMN_CHILDREN_KEY])) { + const children = row[COLUMN_CHILDREN_KEY].map((r: any) => pickVisible(r)); + if (children.length) { + result[COLUMN_CHILDREN_KEY] = children; + } + } + return result; + }; + + const dataToSave = Array.isArray(allDisplayData) + ? allDisplayData.map((r: any) => pickVisible(r)) + : allDisplayData; + + saveDataAsFile({ + data: dataToSave, + filename: fileName, + fileType: "csv", + delimiter, + }); + } catch (_e) { + // Fallback to previous behavior if anything goes wrong + saveDataAsFile({ + data: allDisplayData, + filename: fileName, + fileType: "csv", + delimiter, + }); + } } refreshData(allQueryNames: Array, setLoading: (loading: boolean) => void) { From 9d5e0aae15726dc3bb9b71feb1e5e79e963216e1 Mon Sep 17 00:00:00 2001 From: Faran Javed Date: Fri, 17 Oct 2025 22:39:56 +0500 Subject: [PATCH 2/2] [Fix]: #1795 remove unnecessary code --- .../src/comps/comps/tableComp/tableComp.tsx | 65 +++---------------- .../src/comps/comps/tableComp/tableUtils.tsx | 3 +- 2 files changed, 10 insertions(+), 58 deletions(-) diff --git a/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx b/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx index a8d151d1e..52b1acf4a 100644 --- a/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx @@ -99,65 +99,16 @@ export class TableImplComp extends TableInitComp implements IContainer { } downloadData(fileName: string) { - const allDisplayData = (this as any).exposingValues["displayData"]; + // displayData already contains only visible columns (filtered in transformDispalyData) + const displayData = (this as any).exposingValues["displayData"]; const delimiter = this.children.toolbar.children.columnSeparator.getView(); - try { - // Build the set of visible column keys as shown to the user (title or dataIndex) - const enableColumnSetting = this.children.toolbar.children.columnSetting.getView(); - const visibleColumnKeys = new Set(); - this.children.columns.getView().forEach((col) => { - const colView = col.getView(); - const isHidden = columnHide({ - hide: colView.hide, - tempHide: colView.tempHide, - enableColumnSetting, - }); - if (!isHidden) { - const headerKey = (colView.title as any) || colView.dataIndex; - if (headerKey) { - visibleColumnKeys.add(String(headerKey)); - } - } - }); - - const pickVisible = (row: any): any => { - const result: any = {}; - // copy only allowed keys - Object.keys(row || {}).forEach((key) => { - if (key !== COLUMN_CHILDREN_KEY && visibleColumnKeys.has(key)) { - result[key] = row[key]; - } - }); - // retain children recursively if present - if (Array.isArray(row?.[COLUMN_CHILDREN_KEY])) { - const children = row[COLUMN_CHILDREN_KEY].map((r: any) => pickVisible(r)); - if (children.length) { - result[COLUMN_CHILDREN_KEY] = children; - } - } - return result; - }; - - const dataToSave = Array.isArray(allDisplayData) - ? allDisplayData.map((r: any) => pickVisible(r)) - : allDisplayData; - - saveDataAsFile({ - data: dataToSave, - filename: fileName, - fileType: "csv", - delimiter, - }); - } catch (_e) { - // Fallback to previous behavior if anything goes wrong - saveDataAsFile({ - data: allDisplayData, - filename: fileName, - fileType: "csv", - delimiter, - }); - } + saveDataAsFile({ + data: displayData, + filename: fileName, + fileType: "csv", + delimiter, + }); } refreshData(allQueryNames: Array, setLoading: (loading: boolean) => void) { diff --git a/client/packages/lowcoder/src/comps/comps/tableComp/tableUtils.tsx b/client/packages/lowcoder/src/comps/comps/tableComp/tableUtils.tsx index fdc5c775d..edb26ca61 100644 --- a/client/packages/lowcoder/src/comps/comps/tableComp/tableUtils.tsx +++ b/client/packages/lowcoder/src/comps/comps/tableComp/tableUtils.tsx @@ -209,7 +209,8 @@ export function transformDispalyData( return oriDisplayData.map((row) => { const transData = _(row) .omit(OB_ROW_ORI_INDEX) - .mapKeys((value, key) => dataIndexTitleDict[key] || key) + .pickBy((value, key) => key in dataIndexTitleDict) // Only include columns in the dictionary + .mapKeys((value, key) => dataIndexTitleDict[key]) .value(); if (Array.isArray(row[COLUMN_CHILDREN_KEY])) { return {