浏览代码

Merge pull request #1526 from thornomad/filterby-array

Expand `filterBy` to accept and array of values
文翼 10 年之前
父节点
当前提交
c8d8d34a46
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 1 1
      docs/_i18n/en/documentation/methods.md
  2. 5 1
      src/bootstrap-table.js

+ 1 - 1
docs/_i18n/en/documentation/methods.md

@@ -258,7 +258,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
     <tr>
     <tr>
         <td>filterBy</td>
         <td>filterBy</td>
         <td>params</td>
         <td>params</td>
-        <td>(Can use only in client-side)Filter data in table, eg. you can filter <code>{age: 10}</code> to show the data only age is equal to 10.</td>
+        <td>(Can use only in client-side) Filter data in table, e.g. you can filter <code>{age: 10}</code> to show the data only age is equal to 10.  You can also filter with an array of values, as in: <code>{age: 10, hairColor: ["blue", "red", "green"]} to find data where age is equal to 10 and hairColor is either blue, red, or green.</td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>selectPage</td>
         <td>selectPage</td>

+ 5 - 1
src/bootstrap-table.js

@@ -1085,7 +1085,11 @@
             // Check filter
             // Check filter
             this.data = f ? $.grep(this.options.data, function (item, i) {
             this.data = f ? $.grep(this.options.data, function (item, i) {
                 for (var key in f) {
                 for (var key in f) {
-                    if (item[key] !== f[key]) {
+                    if ($.isArray(f[key])) {
+                        if ($.inArray(item[key], f[key]) === -1) {
+                            return false;
+                        }
+                    } else if (item[key] !== f[key]) {
                         return false;
                         return false;
                     }
                     }
                 }
                 }