update Table tree

This commit is contained in:
梁灏 2020-01-03 17:45:27 +08:00
parent 40f055f904
commit 6118c2c8d1
2 changed files with 28 additions and 7 deletions

View file

@ -1,6 +1,6 @@
<template>
<div style="margin: 100px;">
<Table border ref="selection" :columns="columns4" :data="data1" row-key></Table>
<Table disabled-hover border ref="selection" :columns="columns4" :data="data1" row-key></Table>
<Button @click="handleSelectAll(true)">Set all selected</Button>
<Button @click="handleSelectAll(false)">Cancel all selected</Button>
</div>

View file

@ -95,10 +95,6 @@
rowExpanded (_index) {
return this.objData[_index] && this.objData[_index]._isExpanded;
},
// todo
rowShowChildren (_index) {
return this.objData[_index] && this.objData[_index]._isShowChildren;
},
handleMouseIn (_index, event) {
event.stopPropagation();
this.$parent.handleMouseIn(_index);
@ -144,6 +140,32 @@
const result = this.getSpan(row, column, rowIndex, columnIndex);
return !(('rowspan' in result && result.rowspan === 0) || ('colspan' in result && result.colspan === 0));
},
isTrShow (rowKey) {
let status = true;
this.data.forEach(row => {
const showChildren = row._isShowChildren;
if (row._rowKey === rowKey) {
status = status && showChildren;
} else if (row.children && row.children.length) {
status = this.getTrStatus(rowKey, row, status && showChildren);
}
});
return status;
},
getTrStatus (rowKey, data, parentStatus) {
let status = parentStatus;
if (data.children && data.children.length) {
data.children.forEach(row => {
const showChildren = row._isShowChildren;
if (row._rowKey === rowKey) {
status = status && showChildren;
} else if (row.children && row.children.length) {
status = this.getTrStatus(rowKey, row, status && showChildren);
}
});
}
return status;
},
getChildNode (h, data, nodes, level = 1) {
if (data.children && data.children.length) {
data.children.forEach((row, index) => {
@ -178,8 +200,7 @@
//
const trStyle = {};
// todo
if (!this.rowShowChildren(row._index)) trStyle.display = 'none';
if (!this.isTrShow(data._rowKey)) trStyle.display = 'none';
const $tableTr = h(TableTr, {
props: {