ソースを参照

Added property to know if

we should save that state of the table

Fix #1176
Dennis Hernández 10 年 前
コミット
15d5370931

+ 6 - 0
src/extensions/cookie/README.md

@@ -47,6 +47,12 @@ Use Plugin: [bootstrap-table-cookie](https://github.com/wenzhixin/bootstrap-tabl
 * description: You must set this property if the cookie property is enabled to set an unique cookie with an identifier for each table in your page or project. You must set this property because we need create cookies with an identifier.
 * default: ``
 
+### cookiesEnabled
+
+* type: Array
+* description: Set this array with the table properties (sortOrder, sortName, pageNumber, pageList, columns, searchText, filterControl) that you want to save
+* default: `['bs.table.sortOrder', 'bs.table.sortName', 'bs.table.pageNumber', 'bs.table.pageList', 'bs.table.columns', 'bs.table.searchText', 'bs.table.filterControl']`
+
 ## This plugin saves
 
 * Sort order

+ 24 - 9
src/extensions/cookie/bootstrap-table-cookie.js

@@ -46,6 +46,10 @@
             return;
         }
 
+        if ($.inArray(cookieName.toLowerCase(), that.options.cookiesEnabled) === -1) {
+            return;
+        }
+
         cookieName = that.options.cookieIdTable + '.' + cookieName;
         if (!cookieName || /^(?:expires|max\-age|path|domain|secure)$/i.test(cookieName)) {
             return false;
@@ -55,11 +59,17 @@
         return true;
     };
 
-    var getCookie = function (tableName, cookieName) {
-        cookieName = tableName + '.' + cookieName;
+    var getCookie = function (that, tableName, cookieName) {
         if (!cookieName) {
             return null;
         }
+
+        if ($.inArray(cookieName.toLowerCase(), that.options.cookiesEnabled) === -1) {
+            return null;
+        }
+
+        cookieName = tableName + '.' + cookieName;
+
         return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
     };
 
@@ -117,6 +127,7 @@
         cookieDomain: null,
         cookieSecure: null,
         cookieIdTable: '',
+        cookiesEnabled: ['bs.table.sortOrder', 'bs.table.sortName', 'bs.table.pageNumber', 'bs.table.pageList', 'bs.table.columns', 'bs.table.searchText', 'bs.table.filterControl'],
         //internal variable
         filterControls: [],
         filterControlValuesLoaded: false
@@ -143,6 +154,10 @@
         this.options.filterControls = [];
         this.options.filterControlValuesLoaded = false;
 
+
+        this.options.cookiesEnabled = typeof this.options.cookiesEnabled === 'string' ?
+            this.options.cookiesEnabled.replace('[', '').replace(']', '').replace(/ /g, '').toLowerCase().split(',') : this.options.cookiesEnabled;
+
         if (this.options.filterControl) {
             var that = this;
             this.$el.on('column-search.bs.table', function (e, field, text) {
@@ -167,7 +182,7 @@
                 setTimeout(function () {
                     if (!that.options.filterControlValuesLoaded) {
                         that.options.filterControlValuesLoaded = true;
-                        var filterControl = JSON.parse(getCookie(that.options.cookieIdTable, cookieIds.filterControl));
+                        var filterControl = JSON.parse(getCookie(that, that.options.cookieIdTable, cookieIds.filterControl));
                         if (filterControl) {
                             var field = null,
                                 result = [],
@@ -208,12 +223,12 @@
             return;
         }
 
-        var sortOrderCookie = getCookie(this.options.cookieIdTable, cookieIds.sortOrder),
-            sortOrderNameCookie = getCookie(this.options.cookieIdTable, cookieIds.sortName),
-            pageNumberCookie = getCookie(this.options.cookieIdTable, cookieIds.pageNumber),
-            pageListCookie = getCookie(this.options.cookieIdTable, cookieIds.pageList),
-            columnsCookie = JSON.parse(getCookie(this.options.cookieIdTable, cookieIds.columns)),
-            searchTextCookie = getCookie(this.options.cookieIdTable, cookieIds.searchText);
+        var sortOrderCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortOrder),
+            sortOrderNameCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortName),
+            pageNumberCookie = getCookie(this, this.options.cookieIdTable, cookieIds.pageNumber),
+            pageListCookie = getCookie(this, this.options.cookieIdTable, cookieIds.pageList),
+            columnsCookie = JSON.parse(getCookie(this, this.options.cookieIdTable, cookieIds.columns)),
+            searchTextCookie = getCookie(this, this.options.cookieIdTable, cookieIds.searchText);
 
         //sortOrder
         this.options.sortOrder = sortOrderCookie ? sortOrderCookie : 'asc';