Skip to content

Commit d4192eb

Browse files
fix: table width and height
1 parent 479295e commit d4192eb

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

packages/drip-table-generator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drip-table-generator",
3-
"version": "3.2.2-alpha.5",
3+
"version": "3.2.2-alpha.6",
44
"description": "A visualization tool for generating schema of drip-table.",
55
"main": "dist/index.min.js",
66
"module": "lib/index.js",

packages/drip-table-generator/src/layouts/table-workstation/editable-table/components/left-columns/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,23 @@ function LeftFixedColumnsInner<
5353
const leftMargins = React.useMemo(() => {
5454
let margin = 0;
5555
if (props.tableConfig.hasSubTable) {
56-
margin += props.tableConfig.configs.bordered ? 49 : 48;
56+
margin += props.tableConfig.configs.bordered ? 50 : 48;
5757
}
5858
if (props.tableConfig.configs.rowSelection) {
5959
margin += props.tableConfig.configs.bordered ? 49 : 48;
6060
}
61-
props.columnList.forEach((columnWrapper, index) => {
62-
const column = columnWrapper.column;
63-
margin += column.width ? formatNumber(String(column.width).replace('px', '').replace('%', '') || 200) as number : 200;
64-
});
61+
for (let i = 0; i < props.columnList.length; i++) {
62+
const column = props.columnList[i].column;
63+
const width = column.width ? formatNumber(String(column.width).replace('px', '').replace('%', '') || 200) as number : 200;
64+
margin += Math.max(width, 120);
65+
}
66+
if (props.columnList.length > 0 && !props.tableConfig.configs.bordered) {
67+
margin += 3;
68+
}
6569
return margin;
6670
}, [props.tableConfig.hasSubTable, props.tableConfig.configs, props.columnList]);
6771
React.useImperativeHandle(ref, () => ({
6872
getRowHeight: () => {
69-
const rowHeight = rowRef.current?.offsetHeight ?? 0;
7073
let maxCellHeight = 0;
7174
for (const element of (rowRef.current?.children || []) as HTMLDivElement[]) {
7275
if (element.children[0]) {
@@ -76,7 +79,7 @@ function LeftFixedColumnsInner<
7679
}
7780
}
7881
}
79-
return (rowRef.current?.children.length || 0) <= 0 ? rowHeight : maxCellHeight;
82+
return maxCellHeight;
8083
},
8184
getSubTableHeight: () => {
8285
const rows = (containerRef.current?.children || []) as HTMLDivElement[];
@@ -102,7 +105,7 @@ function LeftFixedColumnsInner<
102105
bordered: props.columnList.length > 0 || props.tableConfig.hasSubTable || props.tableConfig.configs.rowSelection,
103106
})}
104107
ref={containerRef}
105-
style={{ width: leftMargins }}
108+
style={{ width: props.tableConfig.hasSubTable ? leftMargins : void 0 }}
106109
>
107110
<div className={classNames(
108111
'jfe-drip-table-generator-workstation-table-row jfe-drip-table-generator-workstation-table-header',

packages/drip-table-generator/src/layouts/table-workstation/editable-table/components/right-columns/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function RightFixedColumnsInner<
4545
const rowRef = React.createRef<HTMLDivElement>();
4646
React.useImperativeHandle(ref, () => ({
4747
getRowHeight: () => {
48-
const rowHeight = rowRef.current?.offsetHeight ?? 0;
4948
let maxCellHeight = 0;
5049
for (const element of (rowRef.current?.children || []) as HTMLDivElement[]) {
5150
if (element.children[0]) {
@@ -55,7 +54,7 @@ function RightFixedColumnsInner<
5554
}
5655
}
5756
}
58-
return (rowRef.current?.children.length || 0) <= 0 ? rowHeight : maxCellHeight;
57+
return maxCellHeight;
5958
},
6059
}));
6160
return (

packages/drip-table-generator/src/layouts/table-workstation/editable-table/index.tsx

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,6 @@ function EditableTable<
4646
const scrollColumnsRef = React.useRef<ScrollableColumnsHandler>(null);
4747
const rightColumnsRef = React.useRef<RightFixedColumnsHandler>(null);
4848

49-
React.useEffect(() => {
50-
const leftHeight = leftColumnsRef.current?.getRowHeight() ?? 0;
51-
const scrollHeight = scrollColumnsRef.current?.getRowHeight() ?? 0;
52-
const rightHeight = rightColumnsRef.current?.getRowHeight() ?? 0;
53-
if ((leftHeight !== scrollHeight || rightHeight !== scrollHeight || leftHeight !== rightHeight) && (
54-
Math.abs(scrollHeight - leftHeight) > 1 && Math.abs(scrollHeight - rightHeight) > 1
55-
)) {
56-
setRowHeight(Math.max(leftHeight, scrollHeight, rightHeight));
57-
}
58-
}, [props.dataSource, props.schema, props.tableConfig]);
59-
60-
React.useEffect(() => {
61-
setTimeout(() => {
62-
const leftHeights = leftColumnsRef.current?.getSubTableHeight() ?? [];
63-
setSubTableHeights(leftHeights);
64-
}, 200);
65-
}, [props.dataSource, props.schema, props.tableConfig, context.tableConfigs]);
66-
67-
React.useEffect(() => {
68-
setTimeout(() => {
69-
const rowHeights = scrollColumnsRef.current?.getRowHeaderHeights() ?? [];
70-
setRowHeaderHeights(rowHeights);
71-
}, 200);
72-
}, [props.dataSource, props.schema, props.tableConfig, context.tableConfigs]);
73-
7449
const tableHeight = React.useMemo(() => {
7550
if (props.tableConfig.configs.scroll?.y && typeof props.tableConfig.configs.scroll?.y !== 'boolean') {
7651
return props.tableConfig.configs.scroll?.y;
@@ -116,6 +91,37 @@ function EditableTable<
11691
leftFixedColumns = filterArray(columnList, item => item.column.fixed === 'left' || (item.column.fixed && item.id < sortableColumns[0].id));
11792
rightFixedColumns = filterArray(columnList, item => item.column.fixed === 'right' || (item.column.fixed && item.id > sortableColumns[0].id));
11893
}
94+
95+
React.useEffect(() => {
96+
const leftHeight = leftColumnsRef.current?.getRowHeight() ?? 0;
97+
const scrollHeight = scrollColumnsRef.current?.getRowHeight() ?? 0;
98+
const rightHeight = rightColumnsRef.current?.getRowHeight() ?? 0;
99+
if (leftFixedColumns.length > 0 && sortableColumns.length > 0 && rightFixedColumns.length > 0
100+
&& (
101+
Math.abs(scrollHeight - leftHeight) > 1 && Math.abs(scrollHeight - rightHeight) > 1
102+
)) {
103+
setRowHeight(Math.max(leftHeight, scrollHeight, rightHeight));
104+
} else if (sortableColumns.length > 0 && rightFixedColumns.length <= 0 && Math.abs(scrollHeight - leftHeight) > 1) {
105+
setRowHeight(Math.max(leftHeight, scrollHeight));
106+
} else if (sortableColumns.length > 0 && leftFixedColumns.length <= 0 && Math.abs(scrollHeight - rightHeight) > 1) {
107+
setRowHeight(Math.max(rightHeight, scrollHeight));
108+
}
109+
}, [props.dataSource, props.schema, props.tableConfig, leftFixedColumns, rightFixedColumns, sortableColumns]);
110+
111+
React.useEffect(() => {
112+
setTimeout(() => {
113+
const leftHeights = leftColumnsRef.current?.getSubTableHeight() ?? [];
114+
setSubTableHeights(leftHeights);
115+
}, 200);
116+
}, [props.dataSource, props.schema, props.tableConfig, context.tableConfigs]);
117+
118+
React.useEffect(() => {
119+
setTimeout(() => {
120+
const rowHeights = scrollColumnsRef.current?.getRowHeaderHeights() ?? [];
121+
setRowHeaderHeights(rowHeights);
122+
}, 200);
123+
}, [props.dataSource, props.schema, props.tableConfig, context.tableConfigs]);
124+
119125
return (
120126
<TableConfigsContext.Consumer>
121127
{({ tableConfigs, setTableColumns }) => (

0 commit comments

Comments
 (0)