ソースを参照

Merge pull request #6045 from wenzhixin/fix/6044

Fixed an issue with custom search filter if the value is an object
文翼 3 年 前
コミット
3a36074fec

+ 17 - 2
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,7 +239,10 @@ $.BootstrapTable = class extends $.BootstrapTable {
             if ($.inArray(key, that.header.fields) !== -1) {
               if (value === undefined || value === null) {
                 tmpItemIsExpected = false
-              } else if (typeof value === 'object') {
+              } else if (typeof value === 'object' && thisColumn.filterCustomSearch) {
+                itemIsExpected.push(that.isValueExpected(rawFilterValue, value, thisColumn, key))
+                return
+              } else if (typeof value === 'object' && Array.isArray(value)) {
                 value.forEach(objectValue => {
                   if (tmpItemIsExpected) {
                     return
@@ -249,6 +253,17 @@ $.BootstrapTable = class extends $.BootstrapTable {
                   }
                   tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key)
                 })
+              } else if (typeof value === 'object' && !Array.isArray(value)) {
+                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()