Browse Source

added an option to search only on displayed/visible columns (#4401)

Dustin Utecht 6 years ago
parent
commit
97356fb641
3 changed files with 17 additions and 1 deletions
  1. 14 0
      site/docs/api/table-options.md
  2. 2 1
      src/bootstrap-table.js
  3. 1 0
      src/constants/index.js

+ 14 - 0
site/docs/api/table-options.md

@@ -794,6 +794,20 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Strict Search](https://examples.bootstrap-table.com/#options/strict-search.html)
 
+## visibleSearch
+
+- **Attribute:** `visible-search`
+
+- **Type:** `Boolean`
+
+- **Detail:**
+
+  set `true` to search only in visible column/data, if the data contains other values which are not displayed they will be ignored while searching.
+
+- **Default:** `false`
+
+- **Example:** [visible search](https://examples.bootstrap-table.com/#options/visible-search.html)
+
 ## showButtonIcons
 
 - **Attribute:** `show-button-icons`

+ 2 - 1
src/bootstrap-table.js

@@ -729,9 +729,10 @@ class BootstrapTable {
         }) : this.options.data
       }
 
+      const visibleFields = this.getVisibleFields()
       this.data = s ? this.data.filter((item, i) => {
         for (let j = 0; j < this.header.fields.length; j++) {
-          if (!this.header.searchables[j]) {
+          if (!this.header.searchables[j] || (this.options.visibleSearch && visibleFields.indexOf(this.header.fields[j]) === -1)) {
             continue
           }
 

+ 1 - 0
src/constants/index.js

@@ -166,6 +166,7 @@ const DEFAULTS = {
   search: false,
   searchOnEnterKey: false,
   strictSearch: false,
+  visibleSearch: false,
   showButtonIcons: true,
   showButtonText: false,
   showSearchButton: false,