From d129670882d0b6f2b63d9fe320dc6eb37aff2272 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 20 Nov 2021 16:29:27 +0800 Subject: [PATCH] fix: table rowSelection deep watch #4889 close #4889 --- components/table/Table.tsx | 36 ++++++++++++++------------ components/table/hooks/useLazyKVMap.ts | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 982f6ffe54..af38e12ad0 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -35,7 +35,7 @@ import defaultLocale from '../locale/en_US'; import type { SizeType } from '../config-provider'; import devWarning from '../vc-util/devWarning'; import type { PropType } from 'vue'; -import { reactive, ref, computed, defineComponent, toRef, watchEffect } from 'vue'; +import { reactive, ref, computed, defineComponent, toRef, watchEffect, watch } from 'vue'; import type { DefaultRecordType } from '../vc-table/interface'; import useBreakpoint from '../_util/hooks/useBreakpoint'; import useConfigInject from '../_util/hooks/useConfigInject'; @@ -487,23 +487,27 @@ const InteralTable = defineComponent< } return props.expandIconColumnIndex; }); - - // ========================== Selections ========================== - const [transformSelectionColumns, selectedKeySet] = useSelection( - computed(() => props.rowSelection), - { - prefixCls, - data: mergedData, - pageData, - getRowKey, - getRecordByKey, - expandType, - childrenColumnName, - locale: tableLocale, - expandIconColumnIndex, - getPopupContainer: computed(() => props.getPopupContainer), + const rowSelection = ref(); + watch( + () => props.rowSelection, + () => { + rowSelection.value = { ...props.rowSelection }; }, + { deep: true }, ); + // ========================== Selections ========================== + const [transformSelectionColumns, selectedKeySet] = useSelection(rowSelection, { + prefixCls, + data: mergedData, + pageData, + getRowKey, + getRecordByKey, + expandType, + childrenColumnName, + locale: tableLocale, + expandIconColumnIndex, + getPopupContainer: computed(() => props.getPopupContainer), + }); const internalRowClassName = (record: any, index: number, indent: number) => { let mergedRowClassName; diff --git a/components/table/hooks/useLazyKVMap.ts b/components/table/hooks/useLazyKVMap.ts index 88e876fd64..2803cca43a 100644 --- a/components/table/hooks/useLazyKVMap.ts +++ b/components/table/hooks/useLazyKVMap.ts @@ -39,7 +39,7 @@ export default function useLazyKVMap( }; }, { - deep: false, + deep: true, immediate: true, }, );