Skip to content

Commit

Permalink
Merge pull request #2561 from XiaoMi/hotfix/table(virtual-max-height)
Browse files Browse the repository at this point in the history
fix(table): virtual maxHeight error
  • Loading branch information
solarjoker authored Aug 1, 2023
2 parents 9a5d40c + 74dcee6 commit 309f627
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
23 changes: 8 additions & 15 deletions packages/ui/table/src/TableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ export const TableBody = forwardRef<HTMLDivElement | null, TableBodyProps>(
)
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 (
<div
ref={scrollBodyElementRef}
Expand All @@ -79,13 +86,6 @@ export const TableBody = forwardRef<HTMLDivElement | null, TableBodyProps>(
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,
}}
Expand Down Expand Up @@ -135,13 +135,6 @@ export const TableBody = forwardRef<HTMLDivElement | null, TableBodyProps>(
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,
}}
Expand Down
6 changes: 5 additions & 1 deletion packages/ui/table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/table/src/use-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -538,7 +538,7 @@ export const useTable = ({

// 平铺的树形结构排序
if (_data.some((d) => d.depth !== 0)) {
_data = flattedTreeSort(_data)
_data = flattedTreeSort<FlattedTableRowData>(_data)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/table/stories/virtual.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export const Virtual = () => {

return (
<>
<h1>Width for Table</h1>
<div className="table-width__wrap" style={{ minWidth: 660, background: '#fff' }}>
<h1>Virtual for Table</h1>
<div className="table-virtual__wrap" style={{ minWidth: 660, background: '#fff' }}>
<Table
fieldKey="name"
columns={column}
Expand Down

0 comments on commit 309f627

Please sign in to comment.