Skip to content

Commit f29b5bf

Browse files
author
luchunyu
committed
fix(table): fix table about checkbox with disabled
1 parent dac451c commit f29b5bf

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/components/table/index.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,12 @@ export default {
223223
updateSelectAll (status) {
224224
this.allChecked = status
225225
this.dataList = this.dataList.map(item => {
226-
this.$set(item, '_checked', status)
226+
if (!item._disabled) {
227+
this.$set(item, '_checked', status)
228+
}
227229
return item
228230
})
229-
if (status) {
230-
this.selection = this.dataList.filter(item => item._checked && !item._disabled)
231-
} else {
232-
this.selection = []
233-
}
231+
this.selection = this.dataList.filter(item => item._checked)
234232
},
235233
onSelectAllChange (status) {
236234
this.updateSelectAll(status)
@@ -243,8 +241,10 @@ export default {
243241
onSelectChange (currentItem, status) {
244242
if (status) {
245243
this.selection.push(currentItem)
244+
} else {
245+
this.selection = this.selection.filter(item => item._indexId !== currentItem._indexId)
246246
}
247-
this.selection = this.selection.filter(item => item._checked && !item._disabled)
247+
this.selection = this.selection.filter(item => item._checked)
248248
this.$nextTick(() => {
249249
this.allChecked = this.selection.length === this.dataList.length
250250
this.indeterminate = this.selection.length > 0 &&
@@ -257,6 +257,7 @@ export default {
257257
const list = []
258258
const selectedList = []
259259
this.datasource && this.datasource.map((item, index) => {
260+
item._indexId = index
260261
item._checked = (item.hasOwnProperty('_checked') && item._checked) || this.allChecked
261262
item._disabled = (item.hasOwnProperty('_disabled') && item._disabled) || this.allChecked
262263
item._showExpand = (item.hasOwnProperty('_showExpand') && item._showExpand)

0 commit comments

Comments
 (0)