react-component / react-component/table

虚拟滚动时,table getRowKey 索引index 为undefined

Open
#1,108 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.4k
Forks
618
Avg merge
10h 19m
Merged PRs (30d)
2

Description

使用虚拟滚动时,设置rowKey有个特殊处理,当唯一值id不存在时,使用索引index代替

rowKey = {(record, index)=>(record?.id || index )}

但索引打印为undefined

看了是因为虚拟滚动Table内部使用rc-virtual-list组件时未传递index,建议支持下索引,或者直接在Table rowKey移除对index的支持,否则使用时容易出现bug

https://github.com/react-component/table/blob/b4a5a03615cfe19b3060d486cb6657fba2934b88/src/VirtualTable/BodyGrid.tsx#L234

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/VirtualTable/BodyGrid.tsx around the linked line and trace how rc-virtual-list supplies row data to Table's rowKey callback. Reproduce virtual scrolling with a rowKey that falls back to index, then verify the chosen behavior: the index is available to rowKey or index-based rowKey support is removed. There are no named tests in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.