浏览代码

Merge pull request #1880 from djhvscf/develop

Improving filter control extension
wenzhixin 10 年之前
父节点
当前提交
796541926e

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

@@ -291,6 +291,13 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
         <td>Enable the search input.</td>
     </tr>
     <tr>
+        <td>searchOnEnterKey</td>
+        <td>data-search-on-enter-key</td>
+        <td>Boolean</td>
+        <td>false</td>
+        <td>The search method will be executed until the Enter key is pressed.</td>
+    </tr>
+    <tr>
         <td>strictSearch</td>
         <td>data-strict-search</td>
         <td>Boolean</td>

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

@@ -247,6 +247,13 @@ Las opciones de la tabla están definidas en `jQuery.fn.bootstrapTable.defaults`
         <td>Habilita el campo para búsqueda.</td>
     </tr>
     <tr>
+        <td>searchOnEnterKey</td>
+        <td>data-search-on-enter-key</td>
+        <td>Boolean</td>
+        <td>false</td>
+        <td>El método será ejecutado hasta que la tecla Enter sea presionada.</td>
+    </tr>
+    <tr>
         <td>strictSearch</td>
         <td>data-strict-search</td>
         <td>Boolean</td>

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

@@ -254,6 +254,13 @@
         <td>Enable the search input.</td>
     </tr>
     <tr>
+        <td>searchOnEnterKey</td>
+        <td>data-search-on-enter-key</td>
+        <td>Boolean</td>
+        <td>false</td>
+        <td>The search method will be executed until the Enter key is pressed.</td>
+    </tr>
+    <tr>
         <td>strictSearch</td>
         <td>data-strict-search</td>
         <td>Boolean</td>

+ 7 - 0
src/bootstrap-table.js

@@ -280,6 +280,7 @@
         paginationPreText: '&lsaquo;',
         paginationNextText: '&rsaquo;',
         search: false,
+        searchOnEnterKey: false,
         strictSearch: false,
         searchAlign: 'right',
         selectItemName: 'btSelectItem',
@@ -1066,6 +1067,12 @@
             this.$toolbar.append(html.join(''));
             $search = this.$toolbar.find('.search input');
             $search.off('keyup drop').on('keyup drop', function (event) {
+                if (that.options.searchOnEnterKey) {
+                    if (event.keyCode !== 13) {
+                        return;
+                    }
+                }
+
                 clearTimeout(timeoutId); // doesn't matter if it's 0
                 timeoutId = setTimeout(function () {
                     that.onSearch(event);

+ 26 - 27
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -9,14 +9,11 @@
     'use strict';
 
     var sprintf = $.fn.bootstrapTable.utils.sprintf;
-    $.extend($.fn.bootstrapTable.defaults.icons, {
-        clear: 'glyphicon-trash icon-clear'
-    });
 
     var addOptionToSelectControl = function (selectControl, value, text) {
         value = $.trim(value);
         selectControl = $(selectControl.get(selectControl.length - 1));
-        if (existsOptionInSelectControl(selectControl, value)) {
+        if (existOptionInSelectControl(selectControl, value)) {
             selectControl.append($("<option></option>")
                 .attr("value", value)
                 .text($('<div />').html(text).text()));
@@ -39,11 +36,11 @@
         }
     };
 
-    var existsOptionInSelectControl = function (selectControl, value) {
+    var existOptionInSelectControl = function (selectControl, value) {
         var options = selectControl.get(selectControl.length - 1).options;
         for (var i = 0; i < options.length; i++) {
             if (options[i].value === value.toString()) {
-                //The value is nor valid to add
+                //The value is not valid to add
                 return false;
             }
         }
@@ -78,10 +75,10 @@
         var header = getCurrentHeader(that),
             searchControls = getCurrentSearchControls(that);
 
-        that.options.values = [];
+        that.options.valuesFilterControl = [];
 
         header.find(searchControls).each(function () {
-            that.options.values.push(
+            that.options.valuesFilterControl.push(
                 {
                     field: $(this).closest('[data-field]').data('field'),
                     value: $(this).val()
@@ -95,10 +92,10 @@
             header = getCurrentHeader(that),
             searchControls = getCurrentSearchControls(that);
 
-        if (that.options.values.length > 0) {
+        if (that.options.valuesFilterControl.length > 0) {
             header.find(searchControls).each(function (index, ele) {
                 field = $(this).closest('[data-field]').data('field');
-                result = $.grep(that.options.values, function (valueObj) {
+                result = $.grep(that.options.valuesFilterControl, function (valueObj) {
                     return valueObj.field === field;
                 });
 
@@ -263,8 +260,7 @@
         filterShowClear: false,
         alignmentSelectControlOptions: undefined,
         //internal variables
-        values: [],
-        that: this,
+        valuesFilterControl: [],
         filterTemplate: {
             input: function (that, field, isVisible) {
                 return sprintf('<input type="text" class="form-control %s" style="width: 100%; visibility: %s">', field, isVisible);
@@ -290,6 +286,10 @@
         'column-search.bs.table': 'onColumnSearch'
     });
 
+    $.extend($.fn.bootstrapTable.defaults.icons, {
+        clear: 'glyphicon-trash icon-clear'
+    });
+
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
         _init = BootstrapTable.prototype.init,
         _initToolbar = BootstrapTable.prototype.initToolbar,
@@ -302,7 +302,7 @@
         if (this.options.filterControl) {
             var that = this;
             //Make sure that the internal variables are set correctly
-            this.options.values = [];
+            this.options.valuesFilterControl = [];
 
             this.$el.on('reset-view.bs.table', function () {
                 //Create controls on $tableHeader if the height is set
@@ -463,19 +463,19 @@
 
     BootstrapTable.prototype.clearFilterControl = function () {
         if (this.options.filterControl && this.options.filterShowClear) {
-            var bootstrap = this,
+            var that = this,
                 cookies = collectBootstrapCookies(),
-                header = getCurrentHeader(bootstrap),
+                header = getCurrentHeader(that),
                 table = header.closest('table'),
-                controls = header.find(getCurrentSearchControls(bootstrap)),
-                search = this.$toolbar.find('.search input'),
+                controls = header.find(getCurrentSearchControls(that)),
+                search = that.$toolbar.find('.search input'),
                 timeoutId = 0;
 
-            $.each(bootstrap.options.values, function (i, item) {
+            $.each(that.options.valuesFilterControl, function (i, item) {
                 item.value = '';
             });
 
-            setValues(bootstrap);
+            setValues(that);
 
             // Clear each type of filter if it exists.
             // Requires the body to reload each time a type of filter is found because we never know
@@ -486,26 +486,25 @@
             }
 
             if (search.length > 0) {
-                bootstrap.resetSearch();
+                that.resetSearch();
             }
 
             // use the default sort order if it exists. do nothing if it does not
-            if (bootstrap.options.sortName !== table.data('sortName') || bootstrap.options.sortOrder !== table.data('sortOrder')) {
-                var sorter = header.find('[data-field="' + $(controls[0]).closest('table').data('sortName') + '"]');
-                bootstrap.onSort(table.data('sortName'), table.data('sortName'));
+            if (that.options.sortName !== table.data('sortName') || that.options.sortOrder !== table.data('sortOrder')) {
+                var sorter = sprintf(header.find('[data-field="%s"]', $(controls[0]).closest('table').data('sortName')));
+                that.onSort(table.data('sortName'), table.data('sortName'));
                 $(sorter).find('.sortable').trigger('click');
             }
 
             // clear cookies once the filters are clean
-
             clearTimeout(timeoutId);
             timeoutId = setTimeout(function () {
                 if (cookies && cookies.length > 0) {
-                    cookies.forEach( function (cookie) {
-                        bootstrap.deleteCookie(cookie);
+                    $.each(cookies, function (i, item) {
+                        that.deleteCookie(item);
                     });
                 }
-            }, this.options.searchTimeOut);
+            }, that.options.searchTimeOut);
         }
     };
 }(jQuery);

+ 5 - 0
src/extensions/mobile/bootstrap-table-mobile.js

@@ -98,6 +98,11 @@
             return;
         }
 
+        if (this.options.minWidth < 100 && this.options.resizable) {
+            console.log("The minWidth when the resizable extension is active should be greater or equal than 100");
+            this.options.minWidth = 100;
+        }
+
         var that = this,
             old = {
                 width: $(window).width(),