浏览代码

Added field for remove method (#4909)

文翼 5 年之前
父节点
当前提交
478cc5e20a
共有 2 个文件被更改,包括 9 次插入5 次删除
  1. 2 3
      site/docs/api/methods.md
  2. 7 2
      src/bootstrap-table.js

+ 2 - 3
site/docs/api/methods.md

@@ -381,8 +381,8 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
 
 
   Remove data from table, the params contain two properties:
   Remove data from table, the params contain two properties:
 
 
-  * `field`: the field name of remove rows.
-  * `values`: the array of values for rows which should be removed.
+  * `field`: the field name of remove rows. If `$index` is not in your fields, you can use this special field `$index` to remove rows by row index.
+  * `values`: the array of values for rows which should be removed. If you use the special field `$index`, you can pass an array of indexes.
 
 
 - **Example:** [Remove](https://examples.bootstrap-table.com/#methods/remove.html)
 - **Example:** [Remove](https://examples.bootstrap-table.com/#methods/remove.html)
 
 
@@ -648,4 +648,3 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter)`.
   * `replace` (optional): set to `true` to replace the row instead of extending.
   * `replace` (optional): set to `true` to replace the row instead of extending.
 
 
 - **Example:** [Update Row](https://examples.bootstrap-table.com/#methods/update-row.html)
 - **Example:** [Update Row](https://examples.bootstrap-table.com/#methods/update-row.html)
-

+ 7 - 2
src/bootstrap-table.js

@@ -2126,12 +2126,17 @@ class BootstrapTable {
     }
     }
 
 
     for (i = len - 1; i >= 0; i--) {
     for (i = len - 1; i >= 0; i--) {
+      let exists = false
       row = this.options.data[i]
       row = this.options.data[i]
 
 
-      if (!row.hasOwnProperty(params.field)) {
+      if (!row.hasOwnProperty(params.field) && params.field !== '$index') {
         continue
         continue
+      } else if (!row.hasOwnProperty(params.field) && params.field === '$index') {
+        exists = params.values.includes(i)
+      } else {
+        exists = params.values.includes(row[params.field])
       }
       }
-      if (params.values.includes(row[params.field])) {
+      if (exists) {
         this.options.data.splice(i, 1)
         this.options.data.splice(i, 1)
         if (this.options.sidePagination === 'server') {
         if (this.options.sidePagination === 'server') {
           this.options.totalRows -= 1
           this.options.totalRows -= 1