浏览代码

Added cardView state to cookies

Dustin Utecht 4 年之前
父节点
当前提交
56c42626d9
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      src/extensions/cookie/bootstrap-table-cookie.js

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

@@ -12,6 +12,7 @@ const UtilsCookie = {
     pageNumber: 'bs.table.pageNumber',
     pageList: 'bs.table.pageList',
     columns: 'bs.table.columns',
+    cardView: 'bs.table.cardView',
     searchText: 'bs.table.searchText',
     reorderColumns: 'bs.table.reorderColumns',
     filterControl: 'bs.table.filterControl',
@@ -280,7 +281,7 @@ $.extend($.fn.bootstrapTable.defaults, {
     'bs.table.pageNumber', 'bs.table.pageList',
     'bs.table.columns', 'bs.table.searchText',
     'bs.table.filterControl', 'bs.table.filterBy',
-    'bs.table.reorderColumns'
+    'bs.table.reorderColumns', 'bs.table.cardView'
   ],
   cookieStorage: 'cookieStorage', // localStorage, sessionStorage, customStorage
   cookieCustomStorageGet: null,
@@ -436,6 +437,11 @@ $.BootstrapTable = class extends $.BootstrapTable {
     UtilsCookie.setCookie(this, UtilsCookie.cookieIds.columns, JSON.stringify(this.getVisibleColumns().map(column => column.field)))
   }
 
+  toggleView () {
+    super.toggleView()
+    UtilsCookie.setCookie(this, UtilsCookie.cookieIds.cardView, this.options.cardView)
+  }
+
   selectPage (page) {
     super.selectPage(page)
     UtilsCookie.setCookie(this, UtilsCookie.cookieIds.pageNumber, page)
@@ -483,6 +489,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
     const pageNumberCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.pageNumber)
     const pageListCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.pageList)
     const searchTextCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.searchText)
+    const cardViewCookie = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.cardView)
 
     const columnsCookieValue = UtilsCookie.getCookie(this, this.options.cookieIdTable, UtilsCookie.cookieIds.columns)
 
@@ -530,6 +537,8 @@ $.BootstrapTable = class extends $.BootstrapTable {
     this.options.pageSize = pageListCookie ? pageListCookie === this.options.formatAllRows() ? pageListCookie : +pageListCookie : this.options.pageSize
     // searchText
     this.options.searchText = searchTextCookie ? searchTextCookie : ''
+    // cardView
+    this.options.cardView = cardViewCookie === 'true' ? cardViewCookie : false
 
     if (columnsCookie) {
       for (const column of this.columns) {