浏览代码

Feature Get a row by unique id

Fix #1015 [help]can I update a row by uniqueid or get a row by unique
id?
Dennis Hernández 10 年之前
父节点
当前提交
fa5873e268
共有 1 个文件被更改,包括 16 次插入3 次删除
  1. 16 3
      src/bootstrap-table.js

+ 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',