ソースを参照

Merge pull request #1016 from djhvscf/master

Feature Get a row by unique id
文翼 10 年 前
コミット
86d80f7dcc

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

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

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

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

+ 24 - 0
docs/_i18n/zh-cn/documentation/methods.md

@@ -59,6 +59,30 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         </td>
     </tr>
     <tr>
+        <td>removeAll</td>
+        <td>-</td>
+        <td>
+        Remove all data from table<br>
+        Example: $('#myTable').bootstrapTable('removeAll')
+        </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>getRowByUniqueId</td>
+        <td>id</td>
+        <td>
+        Get data from table, the row that contains the id passed by parameter<br>
+        Example: $('#myTable').bootstrapTable('getRowByUniqueId', "122")
+        </td>
+    </tr>
+    <tr>
         <td>insertRow</td>
         <td>params</td>
         <td>

+ 16 - 3
src/bootstrap-table.js

@@ -1938,9 +1938,10 @@
         }
     };
 
-    BootstrapTable.prototype.removeByUniqueId = function (id) {
+    BootstrapTable.prototype.getRowByUniqueId = function (id) {
         var uniqueId = this.options.uniqueId,
             len = this.options.data.length,
+            dataRow = undefined,
             i, row;
 
         for (i = len - 1; i >= 0; i--) {
@@ -1961,10 +1962,22 @@
             }
 
             if (row[uniqueId] === id) {
-                this.options.data.splice(i, 1);
+                dataRow = row;
+                break;
             }
         }
 
+        return dataRow;
+    };
+
+    BootstrapTable.prototype.removeByUniqueId = function (id) {
+        var len = this.options.data.length,
+            row = this.getRowByUniqueId(id);
+
+        if (row) {
+            this.options.data.splice(this.options.data.indexOf(row), 1);
+        }
+
         if (len === this.options.data.length) {
             return;
         }
@@ -2280,7 +2293,7 @@
         'getSelections', 'getAllSelections', 'getData',
         'load', 'append', 'prepend', 'remove', 'removeAll',
         'insertRow', 'updateRow', 'updateCell', 'removeByUniqueId',
-        'showRow', 'hideRow', 'getRowsHidden',
+        'getRowByUniqueId', 'showRow', 'hideRow', 'getRowsHidden',
         'mergeCells',
         'checkAll', 'uncheckAll',
         'check', 'uncheck',