diff --git a/packages/ui/table/src/TableBody.tsx b/packages/ui/table/src/TableBody.tsx index 679a60004..ad5c08548 100644 --- a/packages/ui/table/src/TableBody.tsx +++ b/packages/ui/table/src/TableBody.tsx @@ -70,7 +70,14 @@ export const TableBody = forwardRef( ) if (showVirtual) { // TODO: avg和summay row的逻辑 - const vMaxHeight = maxHeight || 300 + + const realHeight = scrollBodyElementRef.current?.getBoundingClientRect().height + const vMaxHeight = maxHeight + ? !isNaN(Number(String(maxHeight).replace(/px/, ''))) + ? Number(maxHeight) + : realHeight + : 300 + return (
( onWheel={onTableBodyScrollMock} style={{ maxHeight: maxHeight !== undefined ? maxHeight : undefined, - // maxHeight 小于 table 实际高度才出现纵向滚动条 - overflowY: - maxHeight !== undefined && - bodyTableRef.current && - bodyTableRef.current.clientHeight > maxHeight - ? 'scroll' - : undefined, // 表格宽度大于div宽度才出现横向滚动条 overflowX: canScroll ? 'scroll' : undefined, }} @@ -135,13 +135,6 @@ export const TableBody = forwardRef( onScroll={onTableBodyScroll} style={{ maxHeight: maxHeight !== undefined ? maxHeight : undefined, - // maxHeight 小于 table 实际高度才出现纵向滚动条 - overflowY: - maxHeight !== undefined && - bodyTableRef.current && - bodyTableRef.current.clientHeight > maxHeight - ? 'scroll' - : undefined, // 表格宽度大于div宽度才出现横向滚动条 overflowX: canScroll ? 'scroll' : undefined, }} diff --git a/packages/ui/table/src/types.ts b/packages/ui/table/src/types.ts index 44402d630..031dc9b78 100644 --- a/packages/ui/table/src/types.ts +++ b/packages/ui/table/src/types.ts @@ -242,13 +242,17 @@ export interface FlattedTableRowData extends TableRowData { /** * 该节点的父节点 */ - parent?: FlattedTableRowData + parent?: FlattedTableRowDataWithChildren /** * 节点所在列表数据中的下标 */ pos?: number } +export interface FlattedTableRowDataWithChildren extends FlattedTableRowData { + children: FlattedTableRowData[] +} + export interface FlattedTableColumnItemData extends TableColumnItem { /** * 树节点唯一 id diff --git a/packages/ui/table/src/use-table.ts b/packages/ui/table/src/use-table.ts index 18b383c32..2b6f0a168 100644 --- a/packages/ui/table/src/use-table.ts +++ b/packages/ui/table/src/use-table.ts @@ -528,7 +528,7 @@ export const useTable = ({ //* *************** 根据排序列处理数据 ************** *// const showData = useMemo(() => { - let _data: FlattedTableRowData[] = cloneTree(transitionData) + let _data = cloneTree(transitionData) if (activeSorterColumn) { const sorter = columns.filter((d) => d.dataKey === activeSorterColumn)[0]?.sorter @@ -538,7 +538,7 @@ export const useTable = ({ // 平铺的树形结构排序 if (_data.some((d) => d.depth !== 0)) { - _data = flattedTreeSort(_data) + _data = flattedTreeSort(_data) } } } diff --git a/packages/ui/table/stories/virtual.stories.tsx b/packages/ui/table/stories/virtual.stories.tsx index b7e6c40fa..ea16f9703 100644 --- a/packages/ui/table/stories/virtual.stories.tsx +++ b/packages/ui/table/stories/virtual.stories.tsx @@ -48,8 +48,8 @@ export const Virtual = () => { return ( <> -

Width for Table

-
+

Virtual for Table

+