浏览代码

Fixed toggleCheck and remove bug (#5437)

文翼 5 年之前
父节点
当前提交
711291c7be
共有 1 个文件被更改,包括 24 次插入20 次删除
  1. 24 20
      src/bootstrap-table.js

+ 24 - 20
src/bootstrap-table.js

@@ -2391,38 +2391,37 @@ class BootstrapTable {
   }
 
   remove (params) {
-    const len = this.options.data.length
-    let i
-    let row
-
-    if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
-      return
-    }
+    let removed = 0
 
-    for (i = len - 1; i >= 0; i--) {
-      let exists = false
+    for (let i = this.options.data.length - 1; i >= 0; i--) {
 
-      row = this.options.data[i]
+      const row = this.options.data[i]
 
       if (!row.hasOwnProperty(params.field) && params.field !== '$index') {
         continue
-      } else if (!row.hasOwnProperty(params.field) && params.field === '$index') {
-        exists = params.values.includes(i)
-      } else {
-        exists = params.values.includes(row[params.field])
       }
-      if (exists) {
+
+      if (
+        !row.hasOwnProperty(params.field) &&
+        params.field === '$index' &&
+        params.values.includes(i) ||
+        params.values.includes(row[params.field])
+      ) {
+        removed++
+
         this.options.data.splice(i, 1)
-        if (this.options.sidePagination === 'server') {
-          this.options.totalRows -= 1
-        }
       }
     }
 
-    if (len === this.options.data.length) {
+    if (!removed) {
       return
     }
 
+    if (this.options.sidePagination === 'server') {
+      this.options.totalRows -= removed
+      this.data = [...this.options.data]
+    }
+
     this.initSearch()
     this.initPagination()
     this.initSort()
@@ -2548,6 +2547,11 @@ class BootstrapTable {
       return
     }
 
+    if (this.options.sidePagination === 'server') {
+      this.options.totalRows -= 1
+      this.data = [...this.options.data]
+    }
+
     this.initSearch()
     this.initPagination()
     this.initBody(true)
@@ -2807,7 +2811,7 @@ class BootstrapTable {
 
   _toggleCheck (checked, index) {
     const $el = this.$selectItem.filter(`[data-index="${index}"]`)
-    const row = this.options.data[index]
+    const row = this.data[index]
 
     if (
       $el.is(':radio') ||