diff --git a/packages/components/table/src/store/index.ts b/packages/components/table/src/store/index.ts index 71a7de0eef..34ab83bc98 100644 --- a/packages/components/table/src/store/index.ts +++ b/packages/components/table/src/store/index.ts @@ -48,6 +48,9 @@ function useStore() { // 没有使用 computed,而是手动更新部分数据 https://github.com/vuejs/vue/issues/6660#issuecomment-331417140 instance.store.updateCurrentRowData() instance.store.updateExpandRows() + instance.store.updateTreeData( + instance.store.states.defaultExpandAll.value + ) if (unref(states.reserveSelection)) { instance.store.assertRowKey() instance.store.updateSelectionByRowKey() diff --git a/packages/components/table/src/store/tree.ts b/packages/components/table/src/store/tree.ts index bb08f6d245..076c3e1acb 100644 --- a/packages/components/table/src/store/tree.ts +++ b/packages/components/table/src/store/tree.ts @@ -66,18 +66,19 @@ function useTree(watcherData: WatcherPropsData) { return res } - const updateTreeData = () => { + const updateTreeData = ( + ifExpandAll = instance.store?.states.defaultExpandAll.value + ) => { const nested = normalizedData.value const normalizedLazyNode_ = normalizedLazyNode.value const keys = Object.keys(nested) const newTreeData = {} if (keys.length) { const oldTreeData = unref(treeData) - const defaultExpandAll = instance.store?.states.defaultExpandAll.value const rootLazyRowKeys = [] const getExpanded = (oldValue, key) => { const included = - defaultExpandAll || + ifExpandAll || (expandRowKeys.value && expandRowKeys.value.indexOf(key) !== -1) return !!((oldValue && oldValue.expanded) || included) } @@ -124,8 +125,18 @@ function useTree(watcherData: WatcherPropsData) { instance.store?.updateTableScrollY() } - watch(() => normalizedData.value, updateTreeData) - watch(() => normalizedLazyNode.value, updateTreeData) + watch( + () => normalizedData.value, + () => { + updateTreeData() + } + ) + watch( + () => normalizedLazyNode.value, + () => { + updateTreeData() + } + ) const updateTreeExpandKeys = (value: string[]) => { expandRowKeys.value = value diff --git a/packages/components/table/src/store/watcher.ts b/packages/components/table/src/store/watcher.ts index 70c0811469..e55e2f7768 100644 --- a/packages/components/table/src/store/watcher.ts +++ b/packages/components/table/src/store/watcher.ts @@ -430,6 +430,7 @@ function useWatcher() { const { updateTreeExpandKeys, toggleTreeExpansion, + updateTreeData, loadOrToggle, states: treeStates, } = useTree({ @@ -490,6 +491,7 @@ function useWatcher() { updateExpandRows, updateCurrentRowData, loadOrToggle, + updateTreeData, states: { rowKey, data,