Skip to content

Commit 28d54a6

Browse files
committed
feat: support listItemHeight
1 parent 9bdcdd4 commit 28d54a6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/VirtualTable/BodyGrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
2929
'expandedKeys',
3030
'childrenColumnName',
3131
]);
32-
const { scrollY, scrollX } = useContext(StaticContext);
32+
const { scrollY, scrollX, listItemHeight } = useContext(StaticContext);
3333

3434
// =========================== Ref ============================
3535
const listRef = React.useRef<ListRef>();
@@ -182,7 +182,7 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
182182
ref={listRef}
183183
className={classNames(tblPrefixCls, `${tblPrefixCls}-virtual`)}
184184
height={scrollY}
185-
itemHeight={24}
185+
itemHeight={listItemHeight || 24}
186186
data={flattenData}
187187
itemKey={item => getRowKey(item.record)}
188188
scrollWidth={scrollX}

src/VirtualTable/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createContext } from '@rc-component/context';
33
export interface StaticContextProps {
44
scrollX: number;
55
scrollY: number;
6+
listItemHeight: number;
67
}
78

89
export const StaticContext = createContext<StaticContextProps>(null);

src/VirtualTable/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ const renderBody: CustomizeScrollBody<any> = (rawData, props) => {
1515
return <Grid ref={ref} data={rawData as any} onScroll={onScroll} />;
1616
};
1717

18-
export interface StaticTableProps<RecordType> extends Omit<TableProps<RecordType>, 'scroll'> {
18+
export interface VirtualTableProps<RecordType> extends Omit<TableProps<RecordType>, 'scroll'> {
1919
scroll: {
2020
x: number;
2121
y: number;
2222
};
23+
listItemHeight?: number;
2324
}
2425

2526
const PRESET_COLUMN_WIDTH = 100;
2627

27-
function VirtualTable<RecordType>(props: StaticTableProps<RecordType>) {
28-
const { columns, scroll, prefixCls = DEFAULT_PREFIX, className } = props;
28+
function VirtualTable<RecordType>(props: VirtualTableProps<RecordType>) {
29+
const { columns, scroll, prefixCls = DEFAULT_PREFIX, className, listItemHeight } = props;
2930

3031
const { x: scrollX, y: scrollY } = scroll || {};
3132
let mergedScrollX = scrollX;
@@ -40,9 +41,15 @@ function VirtualTable<RecordType>(props: StaticTableProps<RecordType>) {
4041
}
4142
}
4243

44+
// ========================= Context ==========================
45+
const context = React.useMemo(
46+
() => ({ scrollX: mergedScrollX, scrollY, listItemHeight }),
47+
[mergedScrollX, scrollY, listItemHeight],
48+
);
49+
4350
// ========================== Render ==========================
4451
return (
45-
<StaticContext.Provider value={{ scrollX: mergedScrollX, scrollY }}>
52+
<StaticContext.Provider value={context}>
4653
<Table
4754
{...props}
4855
className={classNames(className, `${prefixCls}-virtual`)}

0 commit comments

Comments
 (0)