Dennis Hernández 10 年 前
コミット
0a07ef7d2e

+ 8 - 0
docs/_i18n/en/documentation/methods.md

@@ -72,6 +72,14 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         </td>
     </tr>
     <tr>
+        <td>removeByUniqueId</td>
+        <td>id</td>
+        <td>
+        Remove data from table, the row that contains the id passed by parameter<br>
+        Example: $('#myTable').bootstrapTable('removeByUniqueId', "122")
+        </td>
+    </tr>
+    <tr>
         <td>insertRow</td>
         <td>params</td>
         <td>

+ 8 - 0
docs/_i18n/es/documentation/methods.md

@@ -68,6 +68,14 @@ Sintaxis para llamar a un método: `$('#table').bootstrapTable('method', paramet
         </td>
     </tr>
     <tr>
+        <td>removeByUniqueId</td>
+        <td>id</td>
+        <td>
+        Se remueve el dato de la tabla que contiene el id pasado por parámetro<br>
+        Ejemplo: $('#myTable').bootstrapTable('removeByUniqueId', "122")
+        </td>
+    </tr>
+    <tr>
         <td>insertRow</td>
         <td>params</td>
         <td>

+ 26 - 1
src/bootstrap-table.js

@@ -1835,6 +1835,31 @@
         }
     };
 
+    BootstrapTable.prototype.removeByUniqueId = function (id) {
+        var uniqueId = this.options.uniqueId,
+            len = this.options.data.length,
+            i, row;
+
+        for (i = len - 1; i >= 0; i--) {
+            row = this.options.data[i];
+
+            if (!row.hasOwnProperty(uniqueId)) {
+                continue;
+            }
+            if (row[uniqueId] === id) {
+                this.options.data.splice(i, 1);
+            }
+        }
+
+        if (len === this.options.data.length) {
+            return;
+        }
+
+        this.initSearch();
+        this.initPagination();
+        this.initBody(true);
+    };
+
     BootstrapTable.prototype.insertRow = function (params) {
         if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
             return;
@@ -1878,7 +1903,7 @@
             }
         }
         return rows;
-    }
+    };
 
     BootstrapTable.prototype.mergeCells = function (options) {
         var row = options.index,