Skip to content

Commit

Permalink
fix: virtual missing renderIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Sep 12, 2023
1 parent 03eb3d4 commit 8bc5e29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/VirtualTable/BodyLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface BodyLineProps<RecordType = any> {

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

const { scrollX, flattenColumns, prefixCls, fixColumn, componentWidth } = useContext(
TableContext,
Expand Down Expand Up @@ -102,6 +102,7 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
colIndex={colIndex}
indent={indent}
index={index}
renderIndex={renderIndex}
record={record}
inverse={extra}
getHeight={getHeight}
Expand Down
31 changes: 21 additions & 10 deletions src/VirtualTable/VirtualCell.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { useContext } from '@rc-component/context';
import classNames from 'classnames';
import * as React from 'react';
import { getCellProps } from '../Body/BodyRow';
import Cell from '../Cell';
import type useRowInfo from '../hooks/useRowInfo';
import type { ColumnType } from '../interface';
import classNames from 'classnames';
import { useContext } from '@rc-component/context';
import { GridContext } from './context';
import type useRowInfo from '../hooks/useRowInfo';

export interface VirtualCellProps<RecordType extends { index: number }> {
export interface VirtualCellProps<RecordType> {
rowInfo: ReturnType<typeof useRowInfo>;
column: ColumnType<RecordType>;
colIndex: number;
indent: number;
index: number;
/** Used for `column.render` */
renderIndex: number;
record: RecordType;

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

function VirtualCell<RecordType extends { index: number } = any>(
props: VirtualCellProps<RecordType>,
) {
const { rowInfo, column, colIndex, indent, index, record, style, className, inverse, getHeight } =
props;
function VirtualCell<RecordType = any>(props: VirtualCellProps<RecordType>) {
const {
rowInfo,
column,
colIndex,
indent,
index,
renderIndex,
record,
style,
className,
inverse,
getHeight,
} = props;

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

Expand Down Expand Up @@ -108,7 +119,7 @@ function VirtualCell<RecordType extends { index: number } = any>(
key={key}
record={record}
index={index}
renderIndex={record.index}
renderIndex={renderIndex}
dataIndex={dataIndex}
render={mergedRender}
shouldCellUpdate={column.shouldCellUpdate}
Expand Down

0 comments on commit 8bc5e29

Please sign in to comment.