ソースを参照

Fix missing first ajax request with filter cookies

Using the cookie extension to save filter values could result in
a missing first ajax request leaving the table empty.
Istvan Pasztor 8 年 前
コミット
10e04fd1c7
1 ファイル変更7 行追加32 行削除
  1. 7 32
      src/extensions/cookie/bootstrap-table-cookie.js

+ 7 - 32
src/extensions/cookie/bootstrap-table-cookie.js

@@ -170,7 +170,6 @@
             var parsedCookieFilters = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl));
 
             if (!bootstrapTable.options.filterControlValuesLoaded && parsedCookieFilters) {
-                bootstrapTable.options.filterControlValuesLoaded = true;
 
                 var cachedFilters = {},
                     header = getCurrentHeader(bootstrapTable),
@@ -193,7 +192,8 @@
                 });
 
                 bootstrapTable.initColumnSearch(cachedFilters);
-                bootstrapTable.refresh();
+                bootstrapTable.options.filterControlValuesLoaded = true;
+                bootstrapTable.initServer();
             }
         }, 250);
     };
@@ -241,7 +241,6 @@
         _onSearch = BootstrapTable.prototype.onSearch;
 
     BootstrapTable.prototype.init = function () {
-        var timeoutId = 0;
         this.options.filterControls = [];
         this.options.filterControlValuesLoaded = false;
 
@@ -276,36 +275,12 @@
     };
 
     BootstrapTable.prototype.initServer = function () {
-        var bootstrapTable = this,
-            selectsWithoutDefaults = [],
-
-            columnHasSelectControl = function (column) {
-                return column.filterControl && column.filterControl === 'select';
-            },
-
-            columnHasDefaultSelectValues = function (column) {
-                return column.filterData && column.filterData !== 'column';
-            },
-
-            cookiesPresent = function() {
-                var cookie = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl));
-                return bootstrapTable.options.cookie && cookie;
-            };
-
-        selectsWithoutDefaults = $.grep(bootstrapTable.columns, function(column) {
-            return columnHasSelectControl(column) && !columnHasDefaultSelectValues(column);
-        });
-
-        // reset variable to original initServer function, so that future calls to initServer
-        // use the original function from this point on.
-        BootstrapTable.prototype.initServer = _initServer;
-
-        // early return if we don't need to populate any select values with cookie values
-        if (this.options.filterControl && cookiesPresent() && selectsWithoutDefaults.length === 0) {
-            return;
+        var bootstrapTable = this;
+        if (bootstrapTable.options.cookie && bootstrapTable.options.filterControl && !bootstrapTable.options.filterControlValuesLoaded) {
+            var cookie = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl));
+            if (cookie)
+                return;
         }
-
-        // call BootstrapTable.prototype.initServer
         _initServer.apply(this, Array.prototype.slice.apply(arguments));
     };