From 4b6025cb9a3ef067680201ec3052bc651e0a0c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Fri, 13 Aug 2021 08:50:28 +0800 Subject: [PATCH] fix(table): `getSelectRows` support multi-page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getSelectRows支持跨页选择 close: #914 --- CHANGELOG.zh_CN.md | 1 + src/components/Table/src/hooks/useRowSelection.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md index eeaa39f9c6a..b3f77493802 100644 --- a/CHANGELOG.zh_CN.md +++ b/CHANGELOG.zh_CN.md @@ -12,6 +12,7 @@ - 修复可编辑单元格未能正确显示`0`值的问题 - 修复 selection-change 事件在取消勾选时未能正确触发的问题 - 修复浅色主题下的全屏状态背景颜色不正确的问题 + - 修复`getSelectRows`不支持远程数据跨页选择时获取完整数据的问题 - **Qrcode** 修复二维码组件在创建时未能及时绘制的问题 - **BasicModal** 修复`helpMessage`属性不起作用的问题 diff --git a/src/components/Table/src/hooks/useRowSelection.ts b/src/components/Table/src/hooks/useRowSelection.ts index ee6fa9eb7d6..f900a531c7d 100644 --- a/src/components/Table/src/hooks/useRowSelection.ts +++ b/src/components/Table/src/hooks/useRowSelection.ts @@ -67,13 +67,19 @@ export function useRowSelection( function setSelectedRowKeys(rowKeys: string[]) { selectedRowKeysRef.value = rowKeys; - selectedRowRef.value = findNodeAll( - toRaw(unref(tableData)), + const allSelectedRows = findNodeAll( + toRaw(unref(tableData)).concat(toRaw(unref(selectedRowRef))), (item) => rowKeys.includes(item[unref(getRowKey) as string]), { children: propsRef.value.childrenColumnName ?? 'children', } ); + const trueSelectedRows: any[] = []; + rowKeys.forEach((key: string) => { + const found = allSelectedRows.find((item) => item[unref(getRowKey) as string] === key); + found && trueSelectedRows.push(found); + }); + selectedRowRef.value = trueSelectedRows; } function setSelectedRows(rows: Recordable[]) {