Browse Source

Merge pull request #5260 from wenzhixin/fix/5259

only save fields of the columns instead the whole internal stuff!
文翼 5 years ago
parent
commit
72dc558347
1 changed files with 14 additions and 3 deletions
  1. 14 3
      src/extensions/cookie/bootstrap-table-cookie.js

+ 14 - 3
src/extensions/cookie/bootstrap-table-cookie.js

@@ -387,13 +387,13 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
 
   _toggleColumn (...args) {
   _toggleColumn (...args) {
     super._toggleColumn(...args)
     super._toggleColumn(...args)
-    UtilsCookie.setCookie(this, UtilsCookie.cookieIds.columns, JSON.stringify(this.getVisibleColumns()))
+    UtilsCookie.setCookie(this, UtilsCookie.cookieIds.columns, JSON.stringify(this.getVisibleColumns().map((column) => column.field)))
   }
   }
 
 
   _toggleAllColumns (...args) {
   _toggleAllColumns (...args) {
     super._toggleAllColumns(...args)
     super._toggleAllColumns(...args)
 
 
-    UtilsCookie.setCookie(this, UtilsCookie.cookieIds.columns, JSON.stringify(this.getVisibleColumns()))
+    UtilsCookie.setCookie(this, UtilsCookie.cookieIds.columns, JSON.stringify(this.getVisibleColumns().map((column) => column.field)))
   }
   }
 
 
   selectPage (page) {
   selectPage (page) {
@@ -468,7 +468,18 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
 
     if (columnsCookie) {
     if (columnsCookie) {
       for (const column of this.columns) {
       for (const column of this.columns) {
-        column.visible = columnsCookie.filter((c) => { return c.field === column.field }).length > 0 || !column.switchable
+        column.visible = columnsCookie.filter((columnField) => {
+          /**
+           * This is needed for the old saved cookies or the table will show no columns!
+           * It can be removed in 2-3 Versions Later!!
+           * TODO: Remove this part some versions later e.g. 1.17.3
+           */
+          if (columnField instanceof Object) {
+            return columnField.field === column.field
+          }
+
+          return columnField === column.field
+        }).length > 0 || !column.switchable
       }
       }
     }
     }
   }
   }