Browse Source

Allow exact match when searching term with accent

With attribute `data-search-accent-neutralise` set to `true`, searching with
a term containing an accent must return a result in case of exact match.

i.e.
Initial condition: `table` tag has `data-search-accent-neutralise="true"`
 - Before this commit, searching `josé` does NOT match data containing `josé`.
 - With this commit, searching `josé` matches data containing `josé`.
Pierre Alaime 4 years ago
parent
commit
f10addf194
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/bootstrap-table.js

+ 5 - 1
src/bootstrap-table.js

@@ -956,9 +956,13 @@ class BootstrapTable {
         return
       }
 
-      const s = this.searchText && (this.fromHtml ? Utils.escapeHTML(this.searchText) : this.searchText).toLowerCase()
+      let s = this.searchText && (this.fromHtml ? Utils.escapeHTML(this.searchText) : this.searchText).toLowerCase()
       const f = Utils.isEmptyObject(this.filterColumns) ? null : this.filterColumns
 
+      if (this.options.searchAccentNeutralise) {
+        s = Utils.normalizeAccent(s)
+      }
+
       // Check filter
       if (typeof this.filterOptions.filterAlgorithm === 'function') {
         this.data = this.options.data.filter(item => this.filterOptions.filterAlgorithm.apply(null, [item, f]))