fix: [el-table] default-expand-all doesn't work (#3321)

close #2776
This commit is contained in:
Alan Wang
2021-09-12 18:00:22 +08:00
committed by GitHub
parent db28c4112f
commit b14f45006c
3 changed files with 21 additions and 5 deletions

View File

@@ -48,6 +48,9 @@ function useStore<T>() {
// 没有使用 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()

View File

@@ -66,18 +66,19 @@ function useTree<T>(watcherData: WatcherPropsData<T>) {
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<T>(watcherData: WatcherPropsData<T>) {
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

View File

@@ -430,6 +430,7 @@ function useWatcher<T>() {
const {
updateTreeExpandKeys,
toggleTreeExpansion,
updateTreeData,
loadOrToggle,
states: treeStates,
} = useTree({
@@ -490,6 +491,7 @@ function useWatcher<T>() {
updateExpandRows,
updateCurrentRowData,
loadOrToggle,
updateTreeData,
states: {
rowKey,
data,