Browse Source

Adding searchOnEnterKey option

Dennis Hernández 8 years ago
parent
commit
45e24894ba

+ 6 - 0
src/extensions/filter-control/README.md

@@ -42,6 +42,12 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 * description: Set to true if you want to disable the control while the server is responding the data. This options will work if the sidePagination is 'server'.
 * description: Set to true if you want to disable the control while the server is responding the data. This options will work if the sidePagination is 'server'.
 * default: `false`
 * default: `false`
 
 
+### searchOnEnterKey
+
+* type: Boolean
+* description: Set to true to fire the search action when the user press the enter key.
+* default: `false`
+
 ## Column options
 ## Column options
 
 
 ### filterControl
 ### filterControl

+ 17 - 0
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -317,6 +317,14 @@
 
 
         if (addedFilterControl) {
         if (addedFilterControl) {
             header.off('keyup', 'input').on('keyup', 'input', function (event) {
             header.off('keyup', 'input').on('keyup', 'input', function (event) {
+                if (that.options.searchOnEnterKey && event.keyCode !== 13) {
+                    return;
+                }
+
+                if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) {
+                    return;
+                }
+
                 clearTimeout(timeoutId);
                 clearTimeout(timeoutId);
                 timeoutId = setTimeout(function () {
                 timeoutId = setTimeout(function () {
                     that.onColumnSearch(event);
                     that.onColumnSearch(event);
@@ -324,6 +332,14 @@
             });
             });
 
 
             header.off('change', 'select').on('change', 'select', function (event) {
             header.off('change', 'select').on('change', 'select', function (event) {
+                if (that.options.searchOnEnterKey && event.keyCode !== 13) {
+                    return;
+                }
+
+                if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) {
+                    return;
+                }
+                
                 clearTimeout(timeoutId);
                 clearTimeout(timeoutId);
                 timeoutId = setTimeout(function () {
                 timeoutId = setTimeout(function () {
                     that.onColumnSearch(event);
                     that.onColumnSearch(event);
@@ -442,6 +458,7 @@
             }
             }
         },
         },
         disableControlWhenSearch: false,
         disableControlWhenSearch: false,
+        searchOnEnterKey: false,
         //internal variables
         //internal variables
         valuesFilterControl: []
         valuesFilterControl: []
     });
     });