djhvscf 4 年之前
父节点
当前提交
8559bc64eb
共有 1 个文件被更改,包括 11 次插入30 次删除
  1. 11 30
      src/extensions/filter-control/bootstrap-table-filter-control.js

+ 11 - 30
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -458,42 +458,23 @@ $.BootstrapTable = class extends $.BootstrapTable {
       this.filterColumnsPartial = {}
     }
 
-    const $currentTarget = $(currentTarget)
-    const currentTargetValue = $currentTarget.val()
-
-    if (Array.isArray(currentTargetValue)) {
-      const filterByArray = []
-      const $field = $currentTarget.closest('[data-field]').data('field')
-
-      for (let i = 0; i < currentTargetValue.length; i++) {
-        const text = currentTargetValue[i] ? currentTargetValue[i].trim() : ''
-
-        this.trigger('column-search', $field, text)
-
-        if (text) {
-          filterByArray.push(text)
-        }
-      }
-      if (filterByArray.length > 0) {
-        const filterObj = {}
-
-        filterObj[$field] = filterByArray
-        this.filterBy(filterObj)
-      } else {
-        this.filterBy({})
-      }
-    } else {
-      const text = currentTargetValue ? currentTargetValue.trim() : ''
-      const $field = $currentTarget.closest('[data-field]').data('field')
-
+    // If searchOnEnterKey is set to true, then we need to iterate over all controls and grab their values.
+    const controls = this.options.searchOnEnterKey ? UtilsFilterControl.getSearchControls(this).toArray() : [currentTarget]
+    
+    controls.forEach((element) => {
+      const $element = $(element) 
+      const elementValue = $element.val()
+      const text = elementValue ? elementValue.trim() : ''
+      const $field = $element.closest('[data-field]').data('field')
+      
       this.trigger('column-search', $field, text)
-
+      
       if (text) {
         this.filterColumnsPartial[$field] = text
       } else {
         delete this.filterColumnsPartial[$field]
       }
-    }
+    });
 
     this.onSearch({ currentTarget }, false)
   }