ソースを参照

Merge pull request #2979 from djhvscf/develop

Fix issue in cookie extension and added triggerSearch method in filterControl extension
文翼 8 年 前
コミット
15a370319e

+ 4 - 2
src/extensions/cookie/bootstrap-table-cookie.js

@@ -1,7 +1,7 @@
 /**
  * @author: Dennis Hernández
  * @webSite: http://djhvscf.github.io/Blog
- * @version: v1.2.2
+ * @version: v1.2.3
  *
  * @update zhixin wen <wenzhixin2010@gmail.com>
  */
@@ -320,7 +320,9 @@
         }
 
         if ((this.options.cookieIdTable === '') || (this.options.cookieExpire === '') || (!cookieEnabled())) {
-            throw new Error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies");
+            console.error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies");
+            this.options.cookie = false; //Make sure that the cookie extension is disabled
+            return;
         }
 
         var sortOrderCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortOrder),

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

@@ -36,6 +36,12 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 * description: Set to true in order to hide the options that are not in the table. This option does not work on server-side pagination.
 * default: `false`
 
+### disableControlWhenSearch
+
+* type: Boolean
+* 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`
+
 ## Column options
 
 ### filterControl
@@ -84,3 +90,9 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 ### onColumnSearch(column-search.bs.table)
 
 * Fired when we are searching into the column data
+
+## Methods
+
+### triggerSearch
+
+* Trigger manually the search action

+ 39 - 1
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -1,7 +1,7 @@
 /**
  * @author: Dennis Hernández
  * @webSite: http://djhvscf.github.io/Blog
- * @version: v2.1.1
+ * @version: v2.1.2
  */
 
 (function ($) {
@@ -441,6 +441,7 @@
                 return sprintf('<input type="text" class="form-control date-filter-control bootstrap-table-filter-control-%s" style="width: 100%; visibility: %s">', field, isVisible);
             }
         },
+        disableControlWhenSearch: false,
         //internal variables
         valuesFilterControl: []
     });
@@ -467,8 +468,13 @@
             return 'Clear Filters';
         }
     });
+
     $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
 
+    $.extend($.fn.bootstrapTable.methods, [
+        'triggerSearch'
+    ]);
+
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
         _init = BootstrapTable.prototype.init,
         _initToolbar = BootstrapTable.prototype.initToolbar,
@@ -509,6 +515,10 @@
                 }
             }).on('column-switch.bs.table', function() {
                 setValues(that);
+            }).on('load-success.bs.table', function() {
+                that.EnableControls(true);
+            }).on('load-error.bs.table', function() {
+                that.EnableControls(true);
             });
         }
         _init.apply(this, Array.prototype.slice.apply(arguments));
@@ -638,6 +648,7 @@
         this.searchText += "randomText";
 
         this.options.pageNumber = 1;
+        this.EnableControls(false);
         this.onSearch(event);
         this.trigger('column-search', $field, text);
     };
@@ -694,4 +705,31 @@
             }, that.options.searchTimeOut);
         }
     };
+
+    BootstrapTable.prototype.triggerSearch = function () {
+        var header = getCurrentHeader(this),
+            searchControls = getCurrentSearchControls(this);
+
+        header.find(searchControls).each(function () {
+            var el = $(this);
+            if(el.is('select')) {
+                el.change();
+            } else {
+                el.keyup();
+            }
+        });
+    };
+
+    BootstrapTable.prototype.EnableControls = function(enable) {
+        if((this.options.disableControlWhenSearch) && (this.options.sidePagination === 'server')) {
+            var header = getCurrentHeader(this),
+            searchControls = getCurrentSearchControls(this);
+
+            if(!enable) {
+                header.find(searchControls).prop('disabled', 'disabled');
+            } else {
+                header.find(searchControls).removeProp('disabled');
+            }
+        }
+    };
 })(jQuery);