Skip to content

Commit 356aaa2

Browse files
authored
fix: VirtualTable missing renderIndex param for column.render (#1019)
* test: test driven * fix: virtual missing renderIndex
1 parent 5262f67 commit 356aaa2

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

src/VirtualTable/BodyLine.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface BodyLineProps<RecordType = any> {
2121

2222
const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) => {
2323
const { data, index, className, rowKey, style, extra, getHeight, ...restProps } = props;
24-
const { record, indent } = data;
24+
const { record, indent, index: renderIndex } = data;
2525

2626
const { scrollX, flattenColumns, prefixCls, fixColumn, componentWidth } = useContext(
2727
TableContext,
@@ -102,6 +102,7 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
102102
colIndex={colIndex}
103103
indent={indent}
104104
index={index}
105+
renderIndex={renderIndex}
105106
record={record}
106107
inverse={extra}
107108
getHeight={getHeight}

src/VirtualTable/VirtualCell.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
import { useContext } from '@rc-component/context';
2+
import classNames from 'classnames';
13
import * as React from 'react';
24
import { getCellProps } from '../Body/BodyRow';
35
import Cell from '../Cell';
6+
import type useRowInfo from '../hooks/useRowInfo';
47
import type { ColumnType } from '../interface';
5-
import classNames from 'classnames';
6-
import { useContext } from '@rc-component/context';
78
import { GridContext } from './context';
8-
import type useRowInfo from '../hooks/useRowInfo';
99

10-
export interface VirtualCellProps<RecordType extends { index: number }> {
10+
export interface VirtualCellProps<RecordType> {
1111
rowInfo: ReturnType<typeof useRowInfo>;
1212
column: ColumnType<RecordType>;
1313
colIndex: number;
1414
indent: number;
1515
index: number;
16+
/** Used for `column.render` */
17+
renderIndex: number;
1618
record: RecordType;
1719

1820
// Follow props is used for RowSpanVirtualCell only
@@ -33,11 +35,20 @@ export function getColumnWidth(colIndex: number, colSpan: number, columnsOffset:
3335
return columnsOffset[colIndex + mergedColSpan] - (columnsOffset[colIndex] || 0);
3436
}
3537

36-
function VirtualCell<RecordType extends { index: number } = any>(
37-
props: VirtualCellProps<RecordType>,
38-
) {
39-
const { rowInfo, column, colIndex, indent, index, record, style, className, inverse, getHeight } =
40-
props;
38+
function VirtualCell<RecordType = any>(props: VirtualCellProps<RecordType>) {
39+
const {
40+
rowInfo,
41+
column,
42+
colIndex,
43+
indent,
44+
index,
45+
renderIndex,
46+
record,
47+
style,
48+
className,
49+
inverse,
50+
getHeight,
51+
} = props;
4152

4253
const { render, dataIndex, className: columnClassName, width: colWidth } = column;
4354

@@ -108,7 +119,7 @@ function VirtualCell<RecordType extends { index: number } = any>(
108119
key={key}
109120
record={record}
110121
index={index}
111-
renderIndex={record.index}
122+
renderIndex={renderIndex}
112123
dataIndex={dataIndex}
113124
render={mergedRender}
114125
shouldCellUpdate={column.shouldCellUpdate}

tests/Virtual.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,22 @@ describe('Table.Virtual', () => {
208208

209209
expect(container.querySelector('.rc-virtual-list')).toHaveAttribute('data-scroll-width', '603');
210210
});
211+
212+
it('render params should correct', () => {
213+
const { container } = getTable({
214+
columns: [
215+
{
216+
width: 93,
217+
render: (_, __, index) => <div className="bamboo">{index}</div>,
218+
},
219+
],
220+
scroll: {
221+
x: 1128,
222+
y: 10,
223+
},
224+
data: [{}],
225+
});
226+
227+
expect(container.querySelector('.bamboo').textContent).toEqual('0');
228+
});
211229
});

0 commit comments

Comments
 (0)