Browse Source

Added the keyEvents table option

Dennis Hernández 10 years ago
parent
commit
807cbde012
2 changed files with 31 additions and 0 deletions
  1. 7 0
      docs/_i18n/en/documentation/table-options.md
  2. 24 0
      src/bootstrap-table.js

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

@@ -368,6 +368,13 @@ The table options is defined in `jQuery.fn.bootstrapTable.defaults`.
         <td>true</td>
         <td>False to disable sortable of all columns.</td>
     </tr>
+	<tr>
+        <td>keyEvents</td>
+        <td>data-key-events</td>
+        <td>Boolean</td>
+        <td>false</td>
+        <td>True to enable the key events. For now when the user presses the "S/s" key the search button will be focused.</td>
+    </tr>
     <tr>
         <td>rowStyle</td>
         <td>data-row-style</td>

+ 24 - 0
src/bootstrap-table.js

@@ -177,6 +177,7 @@
         sortable: true,
         maintainSelected: false,
         searchTimeOut: 500,
+        keyEvents: false,
         iconSize: undefined,
         iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
         icons: {
@@ -334,6 +335,7 @@
         this.initPagination();
         this.initBody();
         this.initServer();
+        this.initKeyEvents();
     };
 
     BootstrapTable.prototype.initContainer = function () {
@@ -1399,6 +1401,28 @@
         }));
     };
 
+    BootstrapTable.prototype.initKeyEvents = function () {
+      if (this.options.keyEvents) {
+          var that = this;
+          $(document).off('keypress').on('keypress', function (e) {
+              if (!that.options.search) {
+                  return;
+              }
+
+              switch (e.keyCode) {
+                  case 115://s
+                  case 83://S
+                      var $search = that.$toolbar.find('.search input');
+                      if(document.activeElement === $search.get(0)){
+                          return true;
+                      }
+                      $search.focus();
+                      return false;
+              }
+          });
+      }
+    };
+
     BootstrapTable.prototype.getCaretHtml = function () {
         return ['<span class="order' + (this.options.sortOrder === 'desc' ? '' : ' dropup') + '">',
             '<span class="caret" style="margin: 10px 5px;"></span>',