ソースを参照

Merge pull request #1592 from sketchman-nyt/feature/updateByUniqueId

Added new feature method: updateByUniqueId (PR to develop)
文翼 10 年 前
コミット
e03c374d5d
2 ファイル変更28 行追加1 行削除
  1. 9 0
      docs/_i18n/en/documentation/methods.md
  2. 19 1
      src/bootstrap-table.js

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

@@ -113,6 +113,15 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         row: the new row data.
         </td>
     </tr>
+    <tr>
+        <td>updateByUniqueId</td>
+        <td>params</td>
+        <td>
+        Update the specified row, the param contains following properties: <br>
+        id: a row id where the id should be the uniqueid field assigned to the table. <br>
+        row: the new row data.
+        </td>
+    </tr>
 	<tr>
         <td>showRow</td>
         <td>params</td>

+ 19 - 1
src/bootstrap-table.js

@@ -2220,6 +2220,24 @@
         this.initBody(true);
     };
 
+    BootstrapTable.prototype.updateByUniqueId = function (params) {
+        var rowId;
+
+        if (!params.hasOwnProperty('id') || !params.hasOwnProperty('row')) {
+            return;
+        }
+
+        rowId = $.inArray(this.getRowByUniqueId(params.id), this.options.data);
+
+        if (rowId === -1) {
+            return;
+        }
+
+        $.extend(this.data[rowId], params.row);
+        this.initSort();
+        this.initBody(true);
+    };
+
     BootstrapTable.prototype.insertRow = function (params) {
         if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
             return;
@@ -2593,7 +2611,7 @@
         'getOptions',
         'getSelections', 'getAllSelections', 'getData',
         'load', 'append', 'prepend', 'remove', 'removeAll',
-        'insertRow', 'updateRow', 'updateCell', 'removeByUniqueId',
+        'insertRow', 'updateRow', 'updateCell', 'updateByUniqueId', 'removeByUniqueId',
         'getRowByUniqueId', 'showRow', 'hideRow', 'getRowsHidden',
         'mergeCells',
         'checkAll', 'uncheckAll',