Skip to content

Commit a591144

Browse files
VdustRmarcosmoura
authored andcommitted
fix(MdTable): emit selected/update event only when selected items really changed (#1585)
* fix(MdTable): only emit selected / update event when selected item(s) really changed fix #1559 * refactor(MdTable): selectedItems check changed beautify
1 parent 9d04824 commit a591144

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/components/MdTable/MdTable.vue

+21-4
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,28 @@
222222
this.MdTable.hasValue = this.hasValue
223223
}
224224
},
225-
'MdTable.selectedItems' (val) {
226-
this.select(val)
225+
'MdTable.selectedItems' (val, old) {
226+
let changed = (() => {
227+
let isValEmpty = !val || val.length === 0
228+
let isOldEmpty = !old || old.length === 0
229+
230+
if (isValEmpty && isOldEmpty) {
231+
return false
232+
} else if (!isValEmpty && !isOldEmpty) {
233+
return (val.length !== old.length) ? true : !val.every((item, index) => item == old[index])
234+
} else {
235+
return true
236+
}
237+
})()
238+
239+
if (changed) {
240+
this.select(val)
241+
}
227242
},
228-
'MdTable.singleSelection' (val) {
229-
this.select(val)
243+
'MdTable.singleSelection' (val, old) {
244+
if (val != old) {
245+
this.select(val)
246+
}
230247
},
231248
mdSelectedValue () {
232249
this.syncSelectedValue()

0 commit comments

Comments
 (0)