mirror of https://github.com/ElemeFE/element
Table: fix ExpandRowKeys change view is error, add ExpandRowKeys .sync modifier support
修复issue #18913pull/21491/head
parent
7f54540b6b
commit
89342f540a
|
@ -25,6 +25,14 @@ Watcher.prototype.mutations = {
|
|||
this.updateAllSelected();
|
||||
|
||||
this.updateTableScrollY();
|
||||
this.$nextTick().then(() => {
|
||||
states.lastDataKeysMap = {};
|
||||
if (Array.isArray(data)) {
|
||||
for (let el of data) {
|
||||
states.lastDataKeysMap[el[states.rowKey]] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
insertColumn(states, column, index, parent) {
|
||||
|
|
|
@ -53,7 +53,13 @@ export default {
|
|||
|
||||
watch: {
|
||||
normalizedData: 'updateTreeData',
|
||||
normalizedLazyNode: 'updateTreeData'
|
||||
normalizedLazyNode: 'updateTreeData',
|
||||
'states.expandRowKeys': {
|
||||
immediate: true,
|
||||
handler: function(n) {
|
||||
this.table && this.table.$emit('update:expandRowKeys', n);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
@ -99,14 +105,20 @@ export default {
|
|||
treeData: oldTreeData,
|
||||
defaultExpandAll,
|
||||
expandRowKeys,
|
||||
lazy
|
||||
lazy,
|
||||
lastDataKeysMap
|
||||
} = this.states;
|
||||
const rootLazyRowKeys = [];
|
||||
const getExpanded = (oldValue, key) => {
|
||||
const included =
|
||||
defaultExpandAll ||
|
||||
(expandRowKeys && expandRowKeys.indexOf(key) !== -1);
|
||||
return !!((oldValue && oldValue.expanded) || included);
|
||||
if (!lastDataKeysMap[key]) {
|
||||
if (defaultExpandAll) {
|
||||
if (expandRowKeys.indexOf(key) === -1) {
|
||||
expandRowKeys.push(key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return expandRowKeys.indexOf(key) !== -1;
|
||||
};
|
||||
// 合并 expanded 与 display,确保数据刷新后,状态不变
|
||||
keys.forEach(key => {
|
||||
|
@ -167,6 +179,18 @@ export default {
|
|||
expanded = typeof expanded === 'undefined' ? !data.expanded : expanded;
|
||||
treeData[id].expanded = expanded;
|
||||
if (oldExpanded !== expanded) {
|
||||
if (expanded) {
|
||||
if (this.states.expandRowKeys.indexOf(`${id}`) === -1) {
|
||||
this.states.expandRowKeys.push(`${id}`);
|
||||
}
|
||||
} else {
|
||||
for (let i = this.states.expandRowKeys.length - 1;i >= 0;i--) {
|
||||
if (`${id}` === this.states.expandRowKeys[i]) {
|
||||
this.states.expandRowKeys.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.table.$emit('expand-change', row, expanded);
|
||||
}
|
||||
this.updateTableScrollY();
|
||||
|
|
|
@ -34,6 +34,8 @@ export default Vue.extend({
|
|||
|
||||
// 渲染的数据来源,是对 table 中的 data 过滤排序后的结果
|
||||
data: [],
|
||||
// 上一次数据, 比对展开状态用
|
||||
lastDataKeysMap: {},
|
||||
|
||||
// 是否包含固定列
|
||||
isComplex: false,
|
||||
|
|
|
@ -619,7 +619,9 @@
|
|||
immediate: true,
|
||||
handler(newVal) {
|
||||
if (newVal) {
|
||||
this.store.setExpandRowKeysAdapter(newVal);
|
||||
this.$nextTick().then(()=>{
|
||||
this.store.setExpandRowKeysAdapter(newVal);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue