Skip to content

Commit

Permalink
Added cookie extension support for the custom view extension
Browse files Browse the repository at this point in the history
  • Loading branch information
UtechtDustin committed Oct 1, 2023
1 parent 7160216 commit 9e130c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion site/docs/extensions/cookie.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ toc: true

Set this array with the table properties (sortOrder, sortName, sortPriority, pageNumber, pageList, hiddenColumns, searchText, filterControl) that you want to save

- **Default:** `['bs.table.sortOrder', 'bs.table.sortName', 'bs.table.sortPriority', 'bs.table.pageNumber', 'bs.table.pageList', 'bs.table.hiddenColumns', 'bs.table.searchText', 'bs.table.filterControl', 'bs.table.cardView']`
- **Default:** `['bs.table.sortOrder', 'bs.table.sortName', 'bs.table.sortPriority', 'bs.table.pageNumber', 'bs.table.pageList', 'bs.table.hiddenColumns', 'bs.table.searchText', 'bs.table.filterControl', 'bs.table.cardView', 'bs.table.customView']`

## Methods

Expand Down
10 changes: 9 additions & 1 deletion src/extensions/cookie/bootstrap-table-cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const UtilsCookie = {
columns: 'bs.table.columns',
hiddenColumns: 'bs.table.hiddenColumns',
cardView: 'bs.table.cardView',
customView: 'bs.table.customView',
searchText: 'bs.table.searchText',
reorderColumns: 'bs.table.reorderColumns',
filterControl: 'bs.table.filterControl',
Expand Down Expand Up @@ -180,7 +181,7 @@ Object.assign($.fn.bootstrapTable.defaults, {
'bs.table.pageNumber', 'bs.table.pageList',
'bs.table.hiddenColumns', 'bs.table.columns', 'bs.table.searchText',
'bs.table.filterControl', 'bs.table.filterBy',
'bs.table.reorderColumns', 'bs.table.cardView'
'bs.table.reorderColumns', 'bs.table.cardView', 'bs.table.customView'
],
cookieStorage: 'cookieStorage', // localStorage, sessionStorage, customStorage
cookieCustomStorageGet: null,
Expand Down Expand Up @@ -377,6 +378,11 @@ $.BootstrapTable = class extends $.BootstrapTable {
UtilsCookie.setCookie(this, UtilsCookie.cookieIds.cardView, this.options.cardView)
}

toggleCustomView () {
super.toggleCustomView()
UtilsCookie.setCookie(this, UtilsCookie.cookieIds.customView, this.customViewDefaultView)
}

selectPage (page) {
super.selectPage(page)
if (!this.options.cookie) {
Expand Down Expand Up @@ -433,6 +439,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
const pageListCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.pageList)
const searchTextCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.searchText)
const cardViewCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.cardView)
const customViewCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.customView)

const columnsCookieValue = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.columns)
const hiddenColumnsCookieValue = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.hiddenColumns)
Expand Down Expand Up @@ -491,6 +498,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
}
// cardView
this.options.cardView = cardViewCookie === 'true' ? cardViewCookie : false
this.customViewDefaultView = customViewCookie === 'true'

if (hiddenColumnsCookie) {
for (const column of this.columns) {
Expand Down

0 comments on commit 9e130c4

Please sign in to comment.