ソースを参照

Fixed an issue with custom search filter if the value is an object (none
array)

Dustin Utecht 3 年 前
コミット
0ec77aa1f8

+ 32 - 12
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -216,7 +216,8 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
         keys.forEach(key => {
           const thisColumn = that.columns[that.fieldsColumnsIndex[key]]
-          const filterValue = (filterPartial[key] || '').toLowerCase()
+          const rawFilterValue = (filterPartial[key] || '');
+          const filterValue = rawFilterValue.toLowerCase()
           let value = Utils.unescapeHTML(Utils.getItemField(item, key, false))
           let tmpItemIsExpected
 
@@ -238,17 +239,36 @@ $.BootstrapTable = class extends $.BootstrapTable {
             if ($.inArray(key, that.header.fields) !== -1) {
               if (value === undefined || value === null) {
                 tmpItemIsExpected = false
-              } else if (typeof value === 'object') {
-                value.forEach(objectValue => {
-                  if (tmpItemIsExpected) {
-                    return
-                  }
-
-                  if (this.options.searchAccentNeutralise) {
-                    objectValue = Utils.normalizeAccent(objectValue)
-                  }
-                  tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
-                })
+              } else if (typeof value === 'object' && Array.isArray(value)) {
+                if (thisColumn.filterCustomSearch) {
+                  tmpItemIsExpected = that.isValueExpected(rawFilterValue, value, thisColumn, key)
+                } else {
+                  value.forEach(objectValue => {
+                    if (tmpItemIsExpected) {
+                      return
+                    }
+
+                    if (this.options.searchAccentNeutralise) {
+                      objectValue = Utils.normalizeAccent(objectValue)
+                    }
+                    tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
+                  })
+                }
+              } else if (typeof value === 'object' && !Array.isArray(value)) {
+                if (thisColumn.filterCustomSearch) {
+                  tmpItemIsExpected = that.isValueExpected(rawFilterValue, value, thisColumn, key)
+                } else {
+                  Object.values(value).forEach(objectValue => {
+                    if (tmpItemIsExpected) {
+                      return
+                    }
+
+                    if (this.options.searchAccentNeutralise) {
+                      objectValue = Utils.normalizeAccent(objectValue)
+                    }
+                    tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
+                  })
+                }
               } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
                 if (this.options.searchAccentNeutralise) {
                   value = Utils.normalizeAccent(value)

+ 1 - 1
src/utils/index.js

@@ -330,7 +330,7 @@ export default {
   },
 
   unescapeHTML (text) {
-    if (!text) {
+    if (typeof text !== 'string' || !text) {
       return text
     }
     return text.toString()