Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const CustomLayout: React.FC<CustomLayoutProps> = (props: PropsWithChildr
col,
row,
dataValue: table.getCellOriginValue(col, row),
value: table.getCellValue(col, row) || '',
value: table.getCellValue(col, row),
rect: {
left: 0,
top: 0,
Expand Down
45 changes: 45 additions & 0 deletions packages/vtable/__tests__/columns/listTable-custom-layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
4 changes: 2 additions & 2 deletions packages/vtable/src/scenegraph/component/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/scenegraph/layout/compute-col-width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading