fix: table rowSelection deep watch #4889

close #4889
pull/4882/head
tangjinzhou 2021-11-20 16:29:27 +08:00
parent 3e05460d09
commit d129670882
2 changed files with 21 additions and 17 deletions

View File

@ -35,7 +35,7 @@ import defaultLocale from '../locale/en_US';
import type { SizeType } from '../config-provider'; import type { SizeType } from '../config-provider';
import devWarning from '../vc-util/devWarning'; import devWarning from '../vc-util/devWarning';
import type { PropType } from 'vue'; 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 type { DefaultRecordType } from '../vc-table/interface';
import useBreakpoint from '../_util/hooks/useBreakpoint'; import useBreakpoint from '../_util/hooks/useBreakpoint';
import useConfigInject from '../_util/hooks/useConfigInject'; import useConfigInject from '../_util/hooks/useConfigInject';
@ -487,11 +487,16 @@ const InteralTable = defineComponent<
} }
return props.expandIconColumnIndex; return props.expandIconColumnIndex;
}); });
const rowSelection = ref();
watch(
() => props.rowSelection,
() => {
rowSelection.value = { ...props.rowSelection };
},
{ deep: true },
);
// ========================== Selections ========================== // ========================== Selections ==========================
const [transformSelectionColumns, selectedKeySet] = useSelection( const [transformSelectionColumns, selectedKeySet] = useSelection(rowSelection, {
computed(() => props.rowSelection),
{
prefixCls, prefixCls,
data: mergedData, data: mergedData,
pageData, pageData,
@ -502,8 +507,7 @@ const InteralTable = defineComponent<
locale: tableLocale, locale: tableLocale,
expandIconColumnIndex, expandIconColumnIndex,
getPopupContainer: computed(() => props.getPopupContainer), getPopupContainer: computed(() => props.getPopupContainer),
}, });
);
const internalRowClassName = (record: any, index: number, indent: number) => { const internalRowClassName = (record: any, index: number, indent: number) => {
let mergedRowClassName; let mergedRowClassName;

View File

@ -39,7 +39,7 @@ export default function useLazyKVMap<RecordType>(
}; };
}, },
{ {
deep: false, deep: true,
immediate: true, immediate: true,
}, },
); );