浏览代码

Merge pull request #555 from macias3/master

Update to methods to select rows by value and documentation
文翼 10 年之前
父节点
当前提交
ebdbfb2983
共有 3 个文件被更改,包括 40 次插入6 次删除
  1. 10 4
      docs/_i18n/en/documentation/events.md
  2. 22 0
      docs/_i18n/en/documentation/methods.md
  3. 8 2
      src/bootstrap-table.js

+ 10 - 4
docs/_i18n/en/documentation/events.md

@@ -77,14 +77,20 @@
     <tr>
         <td>onCheckAll</td>
         <td>check-all.bs.table</td>
-        <td>none</td>
-        <td>Fires when user check all rows.</td>
+        <td>rows</td>
+        <td>
+        Fires when user check all rows, the parameters contains: <br>
+        rows: array of records corresponding to newly checked rows.
+        </td>
     </tr>
     <tr>
         <td>onUncheckAll</td>
         <td>uncheck-all.bs.table</td>
-        <td>none</td>
-        <td>Fires when user uncheck all rows.</td>
+        <td>rows</td>
+        <td>
+        Fires when user uncheck all rows, the parameters contains: <br>
+        rows: array of records corresponding to previously checked rows.
+        </td>
     </tr>
     <tr>
         <td>onLoadSuccess</td>

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

@@ -122,6 +122,28 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>Uncheck a row, the row index start with 0.</td>
     </tr>
     <tr>
+        <td>checkBy</td>
+        <td>params</td>
+        <td>
+        Check a row by array of values, the params contains:<br>
+        field: name of the field used to find records<br>
+        values: array of values for rows to check<br>
+        Example: <br>
+        $("#table").bootstrapTable("checkBy", {field:"field_name", values:["value1","value2","value3"]})
+        </td>
+    </tr>
+    <tr>
+        <td>uncheckBy</td>
+        <td>params</td>
+        <td>
+        Uncheck a row by array of values, the params contains:<br>
+        field: name of the field used to find records<br>
+        values: array of values for rows to uncheck<br>
+        Example: <br>
+        $("#table").bootstrapTable("uncheckBy", {field:"field_name", values:["value1","value2","value3"]})
+        </td>
+    </tr>
+    <tr>
         <td>resetView</td>
         <td>params</td>
         <td>Reset the bootstrap table view, for example reset the table height.</td>

+ 8 - 2
src/bootstrap-table.js

@@ -1554,10 +1554,16 @@
     };
     
     BootstrapTable.prototype.checkBy_ = function (checked, obj) {
+        if(!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
+            return;
+        }
+        
         var that = this;
-        var is_array = $.isArray(obj.value);
         $.each(this.data, function (index, row) {
-            if(is_array ? $.inArray(row[obj.field], obj.value) != -1 : row[obj.field] == obj.value) {
+            if(!row.hasOwnProperty(obj.field)) {
+                return false;
+            }
+            if($.inArray(row[obj.field], obj.values) != -1) {
                 that.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
                 row[that.header.stateField] = checked;
                 that.trigger(checked ? 'check' : 'uncheck', row);