Skip to content

Commit 5eb812e

Browse files
fix: table height sync
1 parent d4192eb commit 5eb812e

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
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.6",
3+
"version": "3.2.2-alpha.7",
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface LeftFixedColumnsProps<
3535
}
3636

3737
export interface LeftFixedColumnsHandler {
38-
getRowHeight: () => number;
38+
getRowHeight: () => number[];
3939
getSubTableHeight: () => number[];
4040
}
4141

@@ -71,6 +71,7 @@ function LeftFixedColumnsInner<
7171
React.useImperativeHandle(ref, () => ({
7272
getRowHeight: () => {
7373
let maxCellHeight = 0;
74+
const rowHeight = rowRef.current?.offsetHeight ?? 0;
7475
for (const element of (rowRef.current?.children || []) as HTMLDivElement[]) {
7576
if (element.children[0]) {
7677
const trueCellHeight = (element.children[0] as HTMLDivElement).offsetHeight + 28;
@@ -79,7 +80,7 @@ function LeftFixedColumnsInner<
7980
}
8081
}
8182
}
82-
return maxCellHeight;
83+
return [rowHeight, maxCellHeight];
8384
},
8485
getSubTableHeight: () => {
8586
const rows = (containerRef.current?.children || []) as HTMLDivElement[];

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface RightFixedColumnsProps<
3232
}
3333

3434
export interface RightFixedColumnsHandler {
35-
getRowHeight: () => number;
35+
getRowHeight: () => number[];
3636
}
3737

3838
function RightFixedColumnsInner<
@@ -46,6 +46,7 @@ function RightFixedColumnsInner<
4646
React.useImperativeHandle(ref, () => ({
4747
getRowHeight: () => {
4848
let maxCellHeight = 0;
49+
const rowHeight = rowRef.current?.offsetHeight ?? 0;
4950
for (const element of (rowRef.current?.children || []) as HTMLDivElement[]) {
5051
if (element.children[0]) {
5152
const trueCellHeight = (element.children[0] as HTMLDivElement).offsetHeight + 28;
@@ -54,7 +55,7 @@ function RightFixedColumnsInner<
5455
}
5556
}
5657
}
57-
return maxCellHeight;
58+
return [rowHeight, maxCellHeight];
5859
},
5960
}));
6061
return (

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface ScrollableColumnsProps<
3232
}
3333

3434
export interface ScrollableColumnsHandler {
35-
getRowHeight: () => number;
35+
getRowHeight: () => number[];
3636
getRowHeaderHeights: () => number[];
3737
}
3838

@@ -48,6 +48,7 @@ function ScrollableColumnsInner<
4848
React.useImperativeHandle(ref, () => ({
4949
getRowHeight: () => {
5050
let maxCellHeight = 0;
51+
const rowHeight = rowRef.current?.offsetHeight ?? 0;
5152
for (const element of (rowRef.current?.children || []) as HTMLDivElement[]) {
5253
if (element.children[0]) {
5354
const trueCellHeight = (element.children[0] as HTMLDivElement).offsetHeight + 28;
@@ -56,7 +57,7 @@ function ScrollableColumnsInner<
5657
}
5758
}
5859
}
59-
return maxCellHeight;
60+
return [rowHeight, maxCellHeight];
6061
},
6162
getRowHeaderHeights: () => {
6263
const rows = (containerRef.current?.children || []) as HTMLDivElement[];

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function EditableTable<
4545
const leftColumnsRef = React.useRef<LeftFixedColumnsHandler>(null);
4646
const scrollColumnsRef = React.useRef<ScrollableColumnsHandler>(null);
4747
const rightColumnsRef = React.useRef<RightFixedColumnsHandler>(null);
48+
const lastRowHeights = React.useRef<number[]>([]);
4849

4950
const tableHeight = React.useMemo(() => {
5051
if (props.tableConfig.configs.scroll?.y && typeof props.tableConfig.configs.scroll?.y !== 'boolean') {
@@ -93,20 +94,22 @@ function EditableTable<
9394
}
9495

9596
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));
97+
const [leftRowHeight, leftCellHeight] = leftColumnsRef.current?.getRowHeight() ?? [0, 0];
98+
const [scrollRowHeight, scrollCellHeight] = scrollColumnsRef.current?.getRowHeight() ?? [0, 0];
99+
const [rightRowHeight, rightCellHeight] = rightColumnsRef.current?.getRowHeight() ?? [0, 0];
100+
if (lastRowHeights.current.length <= 0) {
101+
if (leftRowHeight !== scrollRowHeight || rightRowHeight !== scrollCellHeight || leftRowHeight !== rightRowHeight) {
102+
setRowHeight(Math.max(leftCellHeight, scrollCellHeight, rightCellHeight) + 1);
103+
lastRowHeights.current = [leftCellHeight, scrollCellHeight, rightCellHeight];
104+
}
105+
} else {
106+
const [lastLeftHeight, lastScrollHeight, lastRightHeight] = lastRowHeights.current ?? [];
107+
if (lastLeftHeight !== leftCellHeight || lastScrollHeight !== scrollCellHeight || lastRightHeight !== rightCellHeight) {
108+
setRowHeight(Math.max(leftCellHeight, scrollCellHeight, rightCellHeight) + 1);
109+
lastRowHeights.current = [leftCellHeight, scrollCellHeight, rightCellHeight];
110+
}
108111
}
109-
}, [props.dataSource, props.schema, props.tableConfig, leftFixedColumns, rightFixedColumns, sortableColumns]);
112+
}, [props.dataSource, props.schema, props.tableConfig]);
110113

111114
React.useEffect(() => {
112115
setTimeout(() => {

0 commit comments

Comments
 (0)