|
|
@@ -12,6 +12,7 @@ const UtilsCookie = {
|
|
|
pageNumber: 'bs.table.pageNumber',
|
|
|
pageList: 'bs.table.pageList',
|
|
|
columns: 'bs.table.columns',
|
|
|
+ hiddenColumns: 'bs.table.hiddenColumns',
|
|
|
cardView: 'bs.table.cardView',
|
|
|
searchText: 'bs.table.searchText',
|
|
|
reorderColumns: 'bs.table.reorderColumns',
|
|
|
@@ -178,7 +179,7 @@ $.extend($.fn.bootstrapTable.defaults, {
|
|
|
cookiesEnabled: [
|
|
|
'bs.table.sortOrder', 'bs.table.sortName', 'bs.table.sortPriority',
|
|
|
'bs.table.pageNumber', 'bs.table.pageList',
|
|
|
- 'bs.table.columns', 'bs.table.searchText',
|
|
|
+ 'bs.table.hiddenColumns', 'bs.table.columns', 'bs.table.searchText',
|
|
|
'bs.table.filterControl', 'bs.table.filterBy',
|
|
|
'bs.table.reorderColumns', 'bs.table.cardView'
|
|
|
],
|
|
|
@@ -361,7 +362,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
if (!this.options.cookie) {
|
|
|
return
|
|
|
}
|
|
|
- UtilsCookie.setCookie(this, UtilsCookie.cookieIds.columns, JSON.stringify(this.getVisibleColumns().map(column => column.field)))
|
|
|
+ UtilsCookie.setCookie(this, UtilsCookie.cookieIds.hiddenColumns, JSON.stringify(this.getHiddenColumns().map(column => column.field)))
|
|
|
}
|
|
|
|
|
|
_toggleAllColumns (...args) {
|
|
|
@@ -369,7 +370,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
if (!this.options.cookie) {
|
|
|
return
|
|
|
}
|
|
|
- UtilsCookie.setCookie(this, UtilsCookie.cookieIds.columns, JSON.stringify(this.getVisibleColumns().map(column => column.field)))
|
|
|
+ UtilsCookie.setCookie(this, UtilsCookie.cookieIds.hiddenColumns, JSON.stringify(this.getHiddenColumns().map(column => column.field)))
|
|
|
}
|
|
|
|
|
|
toggleView () {
|
|
|
@@ -435,6 +436,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
const cardViewCookie = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.cardView)
|
|
|
|
|
|
const columnsCookieValue = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.columns)
|
|
|
+ const hiddenColumnsCookieValue = UtilsCookie.getCookie(this, UtilsCookie.cookieIds.hiddenColumns)
|
|
|
|
|
|
if (typeof columnsCookieValue === 'boolean' && !columnsCookieValue) {
|
|
|
throw new Error('The cookie value of filterBy must be a json!')
|
|
|
@@ -448,6 +450,14 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
throw new Error('Could not parse the json of the columns cookie!', columnsCookieValue)
|
|
|
}
|
|
|
|
|
|
+ let hiddenColumnsCookie = {}
|
|
|
+
|
|
|
+ try {
|
|
|
+ hiddenColumnsCookie = JSON.parse(hiddenColumnsCookieValue)
|
|
|
+ } catch (e) {
|
|
|
+ throw new Error('Could not parse the json of the hidden columns cookie!', hiddenColumnsCookieValue)
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
sortPriorityCookie = JSON.parse(sortPriorityCookie)
|
|
|
} catch (e) {
|
|
|
@@ -483,7 +493,22 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
// cardView
|
|
|
this.options.cardView = cardViewCookie === 'true' ? cardViewCookie : false
|
|
|
|
|
|
- if (columnsCookie) {
|
|
|
+ if (hiddenColumnsCookie) {
|
|
|
+ for (const column of this.columns) {
|
|
|
+ column.visible = !hiddenColumnsCookie.filter(columnField => {
|
|
|
+ if (this.isSelectionColumn(column)) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ return columnField === column.field
|
|
|
+ }).length > 0 || !column.switchable
|
|
|
+ }
|
|
|
+ } else if (columnsCookie) {
|
|
|
+ /**
|
|
|
+ * This is needed for the old saved cookies!
|
|
|
+ * It can be removed in 2-3 Versions Later!!
|
|
|
+ * TODO: Remove this part (column cookie) some versions later e.g. 1.22.0
|
|
|
+ */
|
|
|
for (const column of this.columns) {
|
|
|
if (!column.switchable) {
|
|
|
continue
|
|
|
@@ -493,11 +518,6 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
if (this.isSelectionColumn(column)) {
|
|
|
return true
|
|
|
}
|
|
|
- /**
|
|
|
- * 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
|
|
|
}
|
|
|
@@ -514,7 +534,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
|
|
|
$.each(UtilsCookie.cookieIds, (key, value) => {
|
|
|
cookies[key] = UtilsCookie.getCookie(bootstrapTable, value)
|
|
|
- if (key === 'columns') {
|
|
|
+ if (key === 'columns' || key === 'hiddenColumns' || key === 'sortPriority') {
|
|
|
cookies[key] = JSON.parse(cookies[key])
|
|
|
}
|
|
|
})
|