Browse Source

Fixes (#3968)

* Fix #3947

* Fix #3906

* Try to fix an issue with onSort

* Improving logic when there is not any value in the controls

* Fix logic when there is not any value in control

* Fix typo

* Fix an issue with cookie extension and filter-control

* Adding new event to filter-control

* Fix a typo

* New Event to filter-control

* Fix event call

* Delete settimeout

* Fix event call
Dennis Hernández 7 years ago
parent
commit
8c7684ea21

+ 2 - 2
src/bootstrap-table.js

@@ -180,7 +180,7 @@
         }
         }
       }
       }
 
 
-      if (typeof func === 'object') {
+      if (func !== null && typeof func === 'object') {
         return func
         return func
       }
       }
 
 
@@ -2443,7 +2443,7 @@
         data = data[this.options.dataField]
         data = data[this.options.dataField]
       } else if (!Array.isArray(data)) { // support fixedScroll
       } else if (!Array.isArray(data)) { // support fixedScroll
         fixedScroll = data.fixedScroll
         fixedScroll = data.fixedScroll
-        data = data.data
+        data = data[this.options.dataField]
       }
       }
 
 
       this.initData(data)
       this.initData(data)

+ 1 - 1
src/extensions/cookie/bootstrap-table-cookie.js

@@ -274,7 +274,7 @@
                 }
                 }
 
 
                 setCookie(that, cookieIds.filterControl, JSON.stringify(that.options.filterControls));
                 setCookie(that, cookieIds.filterControl, JSON.stringify(that.options.filterControls));
-            }).on('post-body.bs.table', initCookieFilters(that));
+            }).on('created-controls.bs.table', initCookieFilters(that));
         }
         }
         _init.apply(this, Array.prototype.slice.apply(arguments));
         _init.apply(this, Array.prototype.slice.apply(arguments));
     };
     };

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

@@ -97,6 +97,10 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 
 
 * Fired when we are searching into the column data
 * Fired when we are searching into the column data
 
 
+### onCreatedControls(created-controls.bs.table)
+
+* Fired when we are searching into the column data
+
 ## Methods
 ## Methods
 
 
 ### triggerSearch
 ### triggerSearch

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

@@ -224,6 +224,8 @@
                 }
                 }
             }
             }
         });
         });
+
+        that.trigger('created-controls');
     };
     };
 
 
     var escapeID = function(id) {
     var escapeID = function(id) {
@@ -438,6 +440,9 @@
         onColumnSearch: function (field, text) {
         onColumnSearch: function (field, text) {
             return false;
             return false;
         },
         },
+        onCreatedControls: function() {
+            return true;
+        },
         filterShowClear: false,
         filterShowClear: false,
         alignmentSelectControlOptions: undefined,
         alignmentSelectControlOptions: undefined,
         filterTemplate: {
         filterTemplate: {
@@ -468,7 +473,8 @@
     });
     });
 
 
     $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
     $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
-        'column-search.bs.table': 'onColumnSearch'
+        'column-search.bs.table': 'onColumnSearch',
+        'created-controls.bs.table': 'onCreatedControls'
     });
     });
 
 
     $.extend($.fn.bootstrapTable.defaults.icons, {
     $.extend($.fn.bootstrapTable.defaults.icons, {
@@ -670,14 +676,33 @@
                 table = header.closest('table'),
                 table = header.closest('table'),
                 controls = header.find(getCurrentSearchControls(that)),
                 controls = header.find(getCurrentSearchControls(that)),
                 search = that.$toolbar.find('.search input'),
                 search = that.$toolbar.find('.search input'),
+                hasValues = false,
                 timeoutId = 0;
                 timeoutId = 0;
 
 
             $.each(that.options.valuesFilterControl, function (i, item) {
             $.each(that.options.valuesFilterControl, function (i, item) {
+                hasValues = hasValues ? true : item.value !== '';
                 item.value = '';
                 item.value = '';
             });
             });
 
 
             setValues(that);
             setValues(that);
 
 
+             // clear cookies once the filters are clean
+             clearTimeout(timeoutId);
+             timeoutId = setTimeout(function () {
+                 if (cookies && cookies.length > 0) {
+                     $.each(cookies, function (i, item) {
+                         if (that.deleteCookie !== undefined) {
+                             that.deleteCookie(item);
+                         }
+                     });
+                 }
+             }, that.options.searchTimeOut);
+
+            //If there is not any value in the controls exit this method
+            if(!hasValues) {
+                return;
+            }
+
             // Clear each type of filter if it exists.
             // 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
             // Requires the body to reload each time a type of filter is found because we never know
             // which ones are going to be present.
             // which ones are going to be present.
@@ -696,22 +721,10 @@
             if (that.options.sortName !== table.data('sortName') || that.options.sortOrder !== table.data('sortOrder')) {
             if (that.options.sortName !== table.data('sortName') || that.options.sortOrder !== table.data('sortOrder')) {
                 var sorter = header.find(sprintf('[data-field="%s"]', $(controls[0]).closest('table').data('sortName')));
                 var sorter = header.find(sprintf('[data-field="%s"]', $(controls[0]).closest('table').data('sortName')));
                 if (sorter.length > 0) {
                 if (sorter.length > 0) {
-                    that.onSort(table.data('sortName'), table.data('sortName'));
+                    that.onSort({type: 'keypress', currentTarget: sorter});
                     $(sorter).find('.sortable').trigger('click');
                     $(sorter).find('.sortable').trigger('click');
                 }
                 }
             }
             }
-
-            // clear cookies once the filters are clean
-            clearTimeout(timeoutId);
-            timeoutId = setTimeout(function () {
-                if (cookies && cookies.length > 0) {
-                    $.each(cookies, function (i, item) {
-                        if (that.deleteCookie !== undefined) {
-                            that.deleteCookie(item);
-                        }
-                    });
-                }
-            }, that.options.searchTimeOut);
         }
         }
     };
     };