[Table] reserveSelectedRowOnPaginate=false 时表头全选包含其他页数据
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react, typescript
Research direction
Start with packages/components/table/hooks/useRowSelect.tsx, especially how the header select handler chooses rows when reserveSelectedRowOnPaginate is false; the issue reports that allTreeRows contains the full data set. Run the provided hook-level reproduction with the listed React test-renderer setup and check that selecting all on a page emits only that page’s keys and selected rows, including after pagination data changes.
Written by the indexing model from the issue text.
Description
tdesign-react 版本
1.18.4。也核对了当前 develop:d31df33c40a774d435fd00580f72d99f4d271cf0,对应 useRowSelect 源码与发布包 source map 一致。
重现步骤
普通非树形表格,6 条数据,每页 2 条,设置 reserveSelectedRowOnPaginate={false},调用表头全选后,onSelectChange 的 keys 和 selectedRowData 包含全部 6 条数据,而不是当前页的 2 条。
下面是调用发布包原始 hook 和实际表头 onChange handler 的最小复现。它使用 React test-renderer,不是完整 Table DOM 或浏览器交互验证;浏览器回归会另行补充。
在空目录安装并将下方代码保存为 repro.jsx:
npm install --save-exact [email protected] [email protected] [email protected] [email protected] [email protected]
npx esbuild repro.jsx --bundle --platform=node --format=cjs --loader:.css=empty --outfile=repro.cjs
NODE_ENV=test node repro.cjs
import React from 'react';
import TestRenderer, { act } from 'react-test-renderer';
import useRowSelect from 'tdesign-react/es/table/hooks/useRowSelect.js';
const data = Array.from({ length: 6 }, (_, i) => ({ id: i + 1 }));
const column = { colKey: 'row-select', type: 'multiple' };
let selection;
let result;
const props = {
data,
columns: [column],
rowKey: 'id',
defaultSelectedRowKeys: [],
pagination: { current: 1, pageSize: 2, total: 6 },
reserveSelectedRowOnPaginate: false,
onSelectChange(keys, context) {
result = { keys, selectedRowData: context.selectedRowData.map(row => row.id) };
},
};
const classes = { disabled: 'disabled', selected: 'selected', checkCell: 'check' };
function Probe() {
selection = useRowSelect(props, classes);
return null;
}
let renderer;
act(() => { renderer = TestRenderer.create(<Probe />); });
console.log('currentPaginateData:', selection.currentPaginateData.map(row => row.id));
act(() => selection.formatToRowSelectColumn(column).title().props.onChange(true));
console.log('onSelectChange:', JSON.stringify(result));
act(() => renderer.unmount());
实际输出:
currentPaginateData: [ 1, 2 ]
onSelectChange: {"keys":[1,2,3,4,5,6],"selectedRowData":[1,2,3,4,5,6]}
期望结果
false 模式下当前页为 [1,2],全选回调的 keys 和 selectedRowData 应仅包含 [1,2]。初始第二页 [3,4] 以及更新当前页数据后也应遵守当前页范围。
当前类型说明 明确说明 false 时全部选中停留在当前页,不跨分页。
实际结果与排查范围
- 第一页、初始第二页、更新分页数据后的 hook 级复现,均返回全部 6 条数据。
- true 模式选择所有页、无分页模式选择全部数据、取消全选,这些对照用例保持通过。
- useRowSelect 中,普通表格的 allTreeRows 仍为完整 data,因此
allTreeRows || currentPaginateData优先取得完整数据。 - 本问题只针对 false 的当前页约定,不把 true 模式跨页全选当成错误,也不涉及树形表格的选择语义。
环境
Linux;Node.js 24.19.0;React / react-test-renderer 18.3.1。以上输出为实际运行结果,目前没有浏览器版本或截图可报告。
已查看 FAQ、当前 CHANGELOG、相关问题与开放 PR。调查和复现使用了 AI 辅助;未声称人工或真实浏览器验证。
- Dominant language
- TypeScript
- Stars
- 967
- Forks
- 376
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 14
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Tencent/tdesign-react
-
[Chatbot] 似乎不支持ag-ui中的interruptsPossibly taken @LzhengH claimed this 22 days ago. Open💪🏻 enhancement
Tencent/tdesign-react#4400 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
💪🏻 enhancement
Difficulty 3/5 1-2 days Newbie friendliness 58/100
Tencent/tdesign-react#4253 · 1 comment ·
Maintainers usually reply within 1 day
-
💪🏻 enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
Tencent/tdesign-react#4246 · 3 comments ·
Maintainers usually reply within 1 day
-
💪🏻 enhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
Tencent/tdesign-react#4215 · 1 comment ·
Maintainers usually reply within 1 day
-
need more info
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Tencent/tdesign-react#4188 · 3 comments ·
Maintainers usually reply within 1 day
All issues in Tencent/tdesign-react
Similar issues
-
Add: YRF Music NepalOpenstreams:add
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
walletbeat/walletbeat#1558 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
hawk-digital-environments/HAWKI#438 ·
Maintainers usually reply within 1 day
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
GiganticMinecraft/seichi-portal-frontend#1165 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day