Table tree support selectAll func

This commit is contained in:
梁灏 2020-01-08 09:37:34 +08:00
parent ec1f67fa7e
commit 3c9452ef2a
2 changed files with 35 additions and 12 deletions

View file

@ -10,6 +10,8 @@
@on-row-dblclick="ordc" @on-row-dblclick="ordc"
@on-select="os" @on-select="os"
@on-select-cancel="osc" @on-select-cancel="osc"
@on-select-all="osa"
@on-select-all-cancel="osac"
ref="selection" ref="selection"
:columns="columns4" :columns="columns4"
:data="data1" :data="data1"
@ -46,7 +48,8 @@
{ {
title: 'Age', title: 'Age',
// key: 'age', // key: 'age',
slot: 'age' slot: 'age',
sortable: true
}, },
{ {
title: 'Date', title: 'Date',
@ -73,7 +76,7 @@
address: 'London No. 1 Lake Park', address: 'London No. 1 Lake Park',
date: '2016-10-01', date: '2016-10-01',
_showChildren: true, _showChildren: true,
_disabled: true, _disabled: false,
children: [ children: [
{ {
id: '10100', id: '10100',
@ -117,7 +120,8 @@
name: '第九', name: '第九',
age: 23, age: 23,
address: '9梵蒂冈人太热疼我', address: '9梵蒂冈人太热疼我',
date: '2016-10-07' date: '2016-10-07',
_disabled: true
}, },
{ {
id: '10102101101', id: '10102101101',
@ -138,7 +142,7 @@
age: 30, age: 30,
address: 'Sydney No. 1 Lake Park', address: 'Sydney No. 1 Lake Park',
date: '2016-10-02', date: '2016-10-02',
_disabled: true, _disabled: false,
}, },
{ {
id: '103', id: '103',
@ -217,12 +221,18 @@
// console.log(index); // console.log(index);
}, },
os (s, r) { os (s, r) {
console.log(s); // console.log(s);
console.log(r); // console.log(r);
}, },
osc (s, r) { osc (s, r) {
console.log(s); console.log(s);
console.log(r); console.log(r);
},
osa (s) {
console.log(s);
},
osac (s) {
console.log(s);
} }
} }
} }

View file

@ -851,11 +851,13 @@
// } // }
// }); // });
for(const data of this.rebuildData){ for (const data of this.rebuildData) {
if(this.objData[data._index]._isDisabled){ const objData = this.objData[data._index];
continue; if (!objData._isDisabled) {
}else{ objData._isChecked = status;
this.objData[data._index]._isChecked = status; }
if (data.children && data.children.length) {
this.selectAllChildren(objData, status);
} }
} }
const selection = this.getSelection(); const selection = this.getSelection();
@ -866,7 +868,18 @@
} }
this.$emit('on-selection-change', selection); this.$emit('on-selection-change', selection);
}, },
selectAllChildren (data, status) {
if (data.children && data.children.length) {
data.children.map(item => {
if (!item._isDisabled) {
item._isChecked = status;
}
if (item.children && item.children.length) {
this.selectAllChildren(item, status);
}
});
}
},
fixedHeader () { fixedHeader () {
if (this.height || this.maxHeight) { if (this.height || this.maxHeight) {
this.$nextTick(() => { this.$nextTick(() => {