From 3ec9e939a5a47b4d8076ea554cc705e8255330b7 Mon Sep 17 00:00:00 2001 From: biubiukam Date: Wed, 24 Jun 2026 16:05:03 +0800 Subject: [PATCH] fix: preserve custom layout falsy values --- ...-custom-layout-value_2026-06-24-08-02.json | 11 +++++ .../table-components/custom/custom-layout.tsx | 2 +- .../columns/listTable-custom-layout.test.ts | 45 +++++++++++++++++++ .../vtable/src/scenegraph/component/custom.ts | 4 +- .../scenegraph/layout/compute-col-width.ts | 2 +- .../scenegraph/layout/compute-row-height.ts | 2 +- 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 common/changes/@visactor/vtable/fix-issue-1949-custom-layout-value_2026-06-24-08-02.json diff --git a/common/changes/@visactor/vtable/fix-issue-1949-custom-layout-value_2026-06-24-08-02.json b/common/changes/@visactor/vtable/fix-issue-1949-custom-layout-value_2026-06-24-08-02.json new file mode 100644 index 0000000000..64ce0ab8b0 --- /dev/null +++ b/common/changes/@visactor/vtable/fix-issue-1949-custom-layout-value_2026-06-24-08-02.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: preserve custom layout falsy values", + "type": "none", + "packageName": "@visactor/vtable" + } + ], + "packageName": "@visactor/vtable", + "email": "biukam.w@gmail.com" +} \ No newline at end of file diff --git a/packages/react-vtable/src/table-components/custom/custom-layout.tsx b/packages/react-vtable/src/table-components/custom/custom-layout.tsx index cf81f9aa76..1bf72f7dae 100644 --- a/packages/react-vtable/src/table-components/custom/custom-layout.tsx +++ b/packages/react-vtable/src/table-components/custom/custom-layout.tsx @@ -138,7 +138,7 @@ export const CustomLayout: React.FC = (props: PropsWithChildr col, row, dataValue: table.getCellOriginValue(col, row), - value: table.getCellValue(col, row) || '', + value: table.getCellValue(col, row), rect: { left: 0, top: 0, diff --git a/packages/vtable/__tests__/columns/listTable-custom-layout.test.ts b/packages/vtable/__tests__/columns/listTable-custom-layout.test.ts index 5f39d66d48..8f263edbdc 100644 --- a/packages/vtable/__tests__/columns/listTable-custom-layout.test.ts +++ b/packages/vtable/__tests__/columns/listTable-custom-layout.test.ts @@ -320,4 +320,49 @@ describe('listTable-custom-layout init test', () => { expect(rectBound.bottom).toBe(240); listTable.release(); }); + + test('custom layout args should preserve falsy cell values', () => { + const falsyValueContainer = createDiv(); + falsyValueContainer.style.position = 'relative'; + falsyValueContainer.style.width = '400px'; + falsyValueContainer.style.height = '300px'; + + const receivedArgs = []; + const createCustomLayout = () => args => { + receivedArgs.push(args); + + return { + rootContainer: new VTable.CustomLayout.Container({ + width: args.rect.width, + height: args.rect.height + }), + renderDefault: false + }; + }; + + const falsyValueTable = new ListTable(falsyValueContainer, { + columns: [ + { + field: 'zero', + title: 'zero', + customLayout: createCustomLayout() + }, + { + field: 'enabled', + title: 'enabled', + customLayout: createCustomLayout() + } + ], + records: [ + { + zero: 0, + enabled: false + } + ] + }); + + expect(receivedArgs.map(args => args.value)).toEqual([0, false]); + expect(receivedArgs.map(args => args.dataValue)).toEqual([0, false]); + falsyValueTable.release(); + }); }); diff --git a/packages/vtable/src/scenegraph/component/custom.ts b/packages/vtable/src/scenegraph/component/custom.ts index e5f23aa28c..6b4b380ad6 100644 --- a/packages/vtable/src/scenegraph/component/custom.ts +++ b/packages/vtable/src/scenegraph/component/custom.ts @@ -57,7 +57,7 @@ export function dealWithCustom( col: range?.start.col ?? col, row: range?.start.row ?? row, dataValue: table.getCellOriginValue(col, row), - value: table.getCellValue(col, row) || '', + value: table.getCellValue(col, row), rect: { left: 0, top: 0, @@ -96,7 +96,7 @@ export function dealWithCustom( col, row, dataValue: table.getCellOriginValue(col, row), - value: table.getCellValue(col, row) || '', + value: table.getCellValue(col, row), rect: { left: 0, top: 0, diff --git a/packages/vtable/src/scenegraph/layout/compute-col-width.ts b/packages/vtable/src/scenegraph/layout/compute-col-width.ts index 24d06de9b8..a2f83fbade 100644 --- a/packages/vtable/src/scenegraph/layout/compute-col-width.ts +++ b/packages/vtable/src/scenegraph/layout/compute-col-width.ts @@ -440,7 +440,7 @@ function computeCustomRenderWidth(col: number, row: number, table: BaseTableAPI) col: cellRange?.start.col ?? col, row: cellRange?.start.row ?? row, dataValue: table.getCellOriginValue(col, row), - value: table.getCellValue(col, row) || '', + value: table.getCellValue(col, row), rect: getCellRect(col, row, table), table, originCol: col, diff --git a/packages/vtable/src/scenegraph/layout/compute-row-height.ts b/packages/vtable/src/scenegraph/layout/compute-row-height.ts index 425361205c..067ce3f2fb 100644 --- a/packages/vtable/src/scenegraph/layout/compute-row-height.ts +++ b/packages/vtable/src/scenegraph/layout/compute-row-height.ts @@ -618,7 +618,7 @@ function computeCustomRenderHeight(col: number, row: number, table: BaseTableAPI col: cellRange?.start.col ?? col, row: cellRange?.start.row ?? row, dataValue: table.getCellOriginValue(col, row), - value: table.getCellValue(col, row) || '', + value: table.getCellValue(col, row), rect: getCellRect(col, row, table), table, originCol: col,