Skip to content

Commit

Permalink
fix(table): fix getSelectRows for treeTable
Browse files Browse the repository at this point in the history
修复getSelectRows不支持树形表格子级数据的问题

fixed: #1003
  • Loading branch information
mynetfan committed Jul 29, 2021
1 parent d2c3618 commit f2b8bb4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- 修复全屏模式下看不到子组件弹出层(popconfirm 以及 select、treeSelect 等编辑组件)的问题
- 修复启用`expandRowByClick`时,点击不可展开的行可能会导致样式错误的问题
- 修复`pagination`属性动态改变不生效的问题
- 修复`getSelectRows`不支持树形表格子级数据的问题
- **Dark Theme** 黑暗主题下的配色问题修正
- 修复`Tree`组件被选中节点的背景颜色
- 修复`Alert`组件的颜色配置
Expand Down
22 changes: 13 additions & 9 deletions src/components/Table/src/hooks/useRowSelection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isFunction } from '/@/utils/is';
import type { BasicTableProps, TableRowSelection } from '../types/table';
import { computed, ref, unref, ComputedRef, Ref, toRaw, watch, nextTick } from 'vue';
import { computed, ComputedRef, nextTick, Ref, ref, toRaw, unref, watch } from 'vue';
import { ROW_KEY } from '../const';
import { omit } from 'lodash-es';
import { findNodeAll } from '/@/utils/helper/treeHelper';

export function useRowSelection(
propsRef: ComputedRef<BasicTableProps>,
Expand All @@ -21,11 +22,12 @@ export function useRowSelection(
return {
selectedRowKeys: unref(selectedRowKeysRef),
hideDefaultSelections: false,
onChange: (selectedRowKeys: string[], selectedRows: Recordable[]) => {
selectedRowKeysRef.value = selectedRowKeys;
selectedRowRef.value = selectedRows;
onChange: (selectedRowKeys: string[]) => {
setSelectedRowKeys(selectedRowKeys);
// selectedRowKeysRef.value = selectedRowKeys;
// selectedRowRef.value = selectedRows;
},
...omit(rowSelection === undefined ? {} : rowSelection, ['onChange']),
...omit(rowSelection, ['onChange']),
};
});

Expand Down Expand Up @@ -64,11 +66,13 @@ export function useRowSelection(

function setSelectedRowKeys(rowKeys: string[]) {
selectedRowKeysRef.value = rowKeys;

const rows = toRaw(unref(tableData)).filter((item) =>
rowKeys.includes(item[unref(getRowKey) as string])
selectedRowRef.value = findNodeAll(
toRaw(unref(tableData)),
(item) => rowKeys.includes(item[unref(getRowKey) as string]),
{
children: propsRef.value.childrenColumnName ?? 'children',
}
);
selectedRowRef.value = rows;
}

function setSelectedRows(rows: Recordable[]) {
Expand Down

0 comments on commit f2b8bb4

Please sign in to comment.