Browse Source

Merge pull request #4311 from wenzhixin/fix/2776

prevent overwriting the searchText
文翼 6 years ago
parent
commit
97b9481811

+ 12 - 11
src/bootstrap-table.js

@@ -669,19 +669,20 @@ class BootstrapTable {
     }
     }
   }
   }
 
 
-  onSearch ({currentTarget, firedByInitSearchText}) {
-    const text = $(currentTarget).val().trim()
+  onSearch ({currentTarget, firedByInitSearchText} = {}) {
+    if (currentTarget !== undefined) {
+      const text = $(currentTarget).val().trim()
 
 
-    // trim search input
-    if (this.options.trimOnSearch && $(currentTarget).val() !== text) {
-      $(currentTarget).val(text)
-    }
+      if (this.options.trimOnSearch && $(currentTarget).val() !== text) {
+        $(currentTarget).val(text)
+      }
 
 
-    if (text === this.searchText) {
-      return
+      if (text === this.searchText) {
+        return
+      }
+      this.searchText = text
+      this.options.searchText = text
     }
     }
-    this.searchText = text
-    this.options.searchText = text
 
 
     if (!firedByInitSearchText) {
     if (!firedByInitSearchText) {
       this.options.pageNumber = 1
       this.options.pageNumber = 1
@@ -694,7 +695,7 @@ class BootstrapTable {
     } else {
     } else {
       this.updatePagination()
       this.updatePagination()
     }
     }
-    this.trigger('search', text)
+    this.trigger('search', this.searchText)
   }
   }
 
 
   initSearch () {
   initSearch () {

+ 1 - 8
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -773,16 +773,9 @@ $.BootstrapTable = class extends $.BootstrapTable {
       delete this.filterColumnsPartial[$field]
       delete this.filterColumnsPartial[$field]
     }
     }
 
 
-    // if the searchText is the same as the previously selected column value,
-    // bootstrapTable will not try searching again (even though the selected column
-    // may be different from the previous search).  As a work around
-    // we're manually appending some text to bootrap's searchText field
-    // to guarantee that it will perform a search again when we call this.onSearch(event)
-    this.searchText += 'randomText'
-
     this.options.pageNumber = 1
     this.options.pageNumber = 1
     this.EnableControls(false)
     this.EnableControls(false)
-    this.onSearch(event)
+    this.onSearch()
     this.trigger('column-search', $field, text)
     this.trigger('column-search', $field, text)
   }
   }