From bd0bc086c1c4103fe5978af54c34b069d78468a6 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 14 Oct 2021 10:42:35 +0800 Subject: [PATCH] fix: table reactive error, close #4756 --- components/table/Table.tsx | 21 +++++++++++---------- components/vc-table/Table.tsx | 19 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 014ed236e..d1a54c180 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -471,6 +471,16 @@ const InteralTable = defineComponent< return mergedData.value.slice((current - 1) * pageSize, current * pageSize); }); + const expandIconColumnIndex = computed(() => { + // Adjust expand icon index, no overwrite expandIconColumnIndex if set. + if (expandType.value === 'nest' && props.expandIconColumnIndex === undefined) { + return props.rowSelection ? 1 : 0; + } else if (props.expandIconColumnIndex! > 0 && props.rowSelection) { + return props.expandIconColumnIndex - 1; + } + return props.expandIconColumnIndex; + }); + // ========================== Selections ========================== const [transformSelectionColumns, selectedKeySet] = useSelection( computed(() => props.rowSelection), @@ -483,7 +493,7 @@ const InteralTable = defineComponent< expandType, childrenColumnName, locale: tableLocale, - expandIconColumnIndex: computed(() => props.expandIconColumnIndex), + expandIconColumnIndex, getPopupContainer: computed(() => props.getPopupContainer), }, ); @@ -509,15 +519,6 @@ const InteralTable = defineComponent< expose({ selectedKeySet, }); - const expandIconColumnIndex = computed(() => { - // Adjust expand icon index, no overwrite expandIconColumnIndex if set. - if (expandType.value === 'nest' && props.expandIconColumnIndex === undefined) { - return props.rowSelection ? 1 : 0; - } else if (props.expandIconColumnIndex! > 0 && props.rowSelection) { - return props.expandIconColumnIndex - 1; - } - return props.expandIconColumnIndex; - }); const indentSize = computed(() => { // Indent size diff --git a/components/vc-table/Table.tsx b/components/vc-table/Table.tsx index ef4682e40..cfab3cd7b 100644 --- a/components/vc-table/Table.tsx +++ b/components/vc-table/Table.tsx @@ -527,17 +527,18 @@ export default defineComponent>({ summaryCollect, }), ); - useProvideBody( reactive({ - ...reactivePick( - props, - 'rowClassName', - 'expandedRowClassName', - 'expandRowByClick', - 'expandedRowRender', - 'expandIconColumnIndex', - 'indentSize', + ...toRefs( + reactivePick( + props, + 'rowClassName', + 'expandedRowClassName', + 'expandRowByClick', + 'expandedRowRender', + 'expandIconColumnIndex', + 'indentSize', + ), ), columns, flattenColumns,