Browse Source

Redefined customSearch option

zhixin 6 years ago
parent
commit
73b870e4d6
2 changed files with 8 additions and 5 deletions
  1. 6 4
      site/docs/api/table-options.md
  2. 2 1
      src/bootstrap-table.js

+ 6 - 4
site/docs/api/table-options.md

@@ -752,16 +752,18 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Detail:**
 
-  The custom search function is executed instead of built-in search function, takes one parameters:
+  The custom search function is executed instead of built-in search function, takes two parameters:
 
+  * `data`: the table data.
   * `text`: the search text.
 
   Example usage:
 
   {% highlight javascript %}
-  function customSearch(text) {
-    //Search logic here.
-    //You must use `this.data` array in order to filter the data. NO use `this.options.data`.
+  function customSearch(data, text) {
+    return data.filter(function (row) {
+      return row.field.indexOf(text) > -1
+    })
   }
   {% endhighlight %}
 

+ 2 - 1
src/bootstrap-table.js

@@ -1281,7 +1281,8 @@
     initSearch () {
       if (this.options.sidePagination !== 'server') {
         if (this.options.customSearch) {
-          Utils.calculateObjectValue(this.options, this.options.customSearch, [this.searchText])
+          this.data = Utils.calculateObjectValue(this.options, this.options.customSearch,
+            [this.options.data, this.searchText])
           return
         }