ソースを参照

Fix Strict filtering required

Fix #1066
Dennis Hernández 10 年 前
コミット
57fe7c9cc4

+ 7 - 0
docs/_i18n/en/documentation/table-options.md

@@ -243,6 +243,13 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
         <td>false</td>
         <td>Enable the search input.</td>
     </tr>
+    <tr>
+        <td>strictSearch</td>
+        <td>data-strict-search</td>
+        <td>Boolean</td>
+        <td>false</td>
+        <td>Enable the strict search.</td>
+    </tr>
 	<tr>
         <td>searchText</td>
         <td>data-search-text</td>

+ 7 - 0
docs/_i18n/es/documentation/table-options.md

@@ -230,6 +230,13 @@ Las opciones de la tabla están definidas en `jQuery.fn.bootstrapTable.defaults`
         <td>false</td>
         <td>Habilita el campo para búsqueda.</td>
     </tr>
+    <tr>
+        <td>strictSearch</td>
+        <td>data-strict-search</td>
+        <td>Boolean</td>
+        <td>false</td>
+        <td>Habilita la busqueda exacta.</td>
+    </tr>
 	<tr>
         <td>searchText</td>
         <td>data-search-text</td>

+ 7 - 0
docs/_i18n/zh-cn/documentation/table-options.md

@@ -238,6 +238,13 @@ The table options is defined in `jQuery.fn.bootstrapTable.defaults`.
         <td>false</td>
         <td>Enable the search input.</td>
     </tr>
+    <tr>
+        <td>strictSearch</td>
+        <td>data-strict-search</td>
+        <td>Boolean</td>
+        <td>false</td>
+        <td>Enable the strict search.</td>
+    </tr>
 	<tr>
         <td>searchText</td>
         <td>data-search-text</td>

+ 11 - 5
src/bootstrap-table.js

@@ -221,6 +221,7 @@
         paginationNextText: '&rsaquo;',
         paginationLastText: '&raquo;',
         search: false,
+        strictSearch: false,
         searchAlign: 'right',
         selectItemName: 'btSelectItem',
         showHeader: true,
@@ -1015,11 +1016,16 @@
                         that.header.formatters[j], [value, item, i], value);
 
                     var index = $.inArray(key, that.header.fields);
-                    if (index !== -1 && that.header.searchables[index] &&
-                        (typeof value === 'string' ||
-                            typeof value === 'number') &&
-                        (value + '').toLowerCase().indexOf(s) !== -1) {
-                        return true;
+                    if (index !== -1 && that.header.searchables[index] && (typeof value === 'string' || typeof value === 'number')) {
+                        if (that.options.strictSearch) {
+                            if ((value + '').toLowerCase() === s) {
+                                return true;
+                            }
+                        } else {
+                            if ((value + '').toLowerCase().indexOf(s) !== -1) {
+                               return true;
+                            }
+                        }
                     }
                 }
                 return false;