From 39c286f140c165dee0ca69ec0a54d021f2940090 Mon Sep 17 00:00:00 2001 From: Alan Wang Date: Thu, 14 Oct 2021 17:38:00 +0800 Subject: [PATCH] fix: table lazy rows can't expand at the first time (#3731) * fix: Table Attributes expand-row-keys has changed, but fold not work * fix: Table lazy column can't expand at the first time * Update packages/components/table/src/store/tree.ts Co-authored-by: jeremywu <15975785+JeremyWuuuuu@users.noreply.github.com> * Update packages/components/table/src/store/tree.ts Co-authored-by: jeremywu <15975785+JeremyWuuuuu@users.noreply.github.com> Co-authored-by: jeremywu <15975785+JeremyWuuuuu@users.noreply.github.com> --- packages/components/table/src/store/tree.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/components/table/src/store/tree.ts b/packages/components/table/src/store/tree.ts index 597d0a4a82..332cc13086 100644 --- a/packages/components/table/src/store/tree.ts +++ b/packages/components/table/src/store/tree.ts @@ -67,6 +67,7 @@ function useTree(watcherData: WatcherPropsData) { } const updateTreeData = ( + ifChangeExpandRowKeys = false, ifExpandAll = instance.store?.states.defaultExpandAll.value ) => { const nested = normalizedData.value @@ -77,10 +78,17 @@ function useTree(watcherData: WatcherPropsData) { const oldTreeData = unref(treeData) const rootLazyRowKeys = [] const getExpanded = (oldValue, key) => { - if (expandRowKeys.value) { - return ifExpandAll || expandRowKeys.value.includes(key) + if (ifChangeExpandRowKeys) { + if (expandRowKeys.value) { + return ifExpandAll || expandRowKeys.value.includes(key) + } else { + return !!(ifExpandAll || oldValue?.expanded) + } } else { - return !!(ifExpandAll || oldValue?.expanded) + const included = + ifExpandAll || + (expandRowKeys.value && expandRowKeys.value.includes(key)) + return !!(oldValue?.expanded || included) } } // 合并 expanded 与 display,确保数据刷新后,状态不变 @@ -126,6 +134,13 @@ function useTree(watcherData: WatcherPropsData) { instance.store?.updateTableScrollY() } + watch( + () => expandRowKeys.value, + () => { + updateTreeData(true) + } + ) + watch( () => normalizedData.value, () => {