|
|
@@ -10,7 +10,6 @@ const UtilsCookie = {
|
|
|
sortPriority: 'bs.table.sortPriority',
|
|
|
pageNumber: 'bs.table.pageNumber',
|
|
|
pageList: 'bs.table.pageList',
|
|
|
- columns: 'bs.table.columns',
|
|
|
hiddenColumns: 'bs.table.hiddenColumns',
|
|
|
cardView: 'bs.table.cardView',
|
|
|
customView: 'bs.table.customView',
|
|
|
@@ -90,15 +89,15 @@ const UtilsCookie = {
|
|
|
d.setTime(d.getTime() + cookieExpire * 1000)
|
|
|
return d.toGMTString()
|
|
|
},
|
|
|
- initCookieFilters (bootstrapTable) {
|
|
|
+ initCookieFilters (that) {
|
|
|
setTimeout(() => {
|
|
|
const parsedCookieFilters = JSON.parse(
|
|
|
- UtilsCookie.getCookie(bootstrapTable, UtilsCookie.cookieIds.filterControl))
|
|
|
+ UtilsCookie.getCookie(that, UtilsCookie.cookieIds.filterControl))
|
|
|
|
|
|
- if (!bootstrapTable._filterControlValuesLoaded && parsedCookieFilters) {
|
|
|
+ if (!that._filterControlValuesLoaded && parsedCookieFilters) {
|
|
|
const cachedFilters = {}
|
|
|
- const header = UtilsCookie.getCurrentHeader(bootstrapTable)
|
|
|
- const searchControls = UtilsCookie.getCurrentSearchControls(bootstrapTable)
|
|
|
+ const header = UtilsCookie.getCurrentHeader(that)
|
|
|
+ const searchControls = UtilsCookie.getCurrentSearchControls(that)
|
|
|
|
|
|
const applyCookieFilters = (element, filteredCookies) => {
|
|
|
filteredCookies.forEach(cookie => {
|
|
|
@@ -125,7 +124,7 @@ const UtilsCookie = {
|
|
|
cachedFilters[cookie.field] = text
|
|
|
} else if (
|
|
|
element.tagName === 'SELECT' &&
|
|
|
- bootstrapTable.options.filterControlContainer
|
|
|
+ that.options.filterControlContainer
|
|
|
) {
|
|
|
element.value = text
|
|
|
cachedFilters[cookie.field] = text
|
|
|
@@ -149,8 +148,8 @@ const UtilsCookie = {
|
|
|
|
|
|
let filterContainer = header
|
|
|
|
|
|
- if (bootstrapTable.options.filterControlContainer) {
|
|
|
- filterContainer = $(`${bootstrapTable.options.filterControlContainer}`)
|
|
|
+ if (that.options.filterControlContainer) {
|
|
|
+ filterContainer = $(`${that.options.filterControlContainer}`)
|
|
|
}
|
|
|
|
|
|
filterContainer.find(searchControls).each(function () {
|
|
|
@@ -160,9 +159,9 @@ const UtilsCookie = {
|
|
|
applyCookieFilters(this, filteredCookies)
|
|
|
})
|
|
|
|
|
|
- bootstrapTable.initColumnSearch(cachedFilters)
|
|
|
- bootstrapTable._filterControlValuesLoaded = true
|
|
|
- bootstrapTable.initServer()
|
|
|
+ that.initColumnSearch(cachedFilters)
|
|
|
+ that._filterControlValuesLoaded = true
|
|
|
+ that.initServer()
|
|
|
}
|
|
|
}, 250)
|
|
|
}
|
|
|
@@ -179,7 +178,7 @@ Object.assign($.fn.bootstrapTable.defaults, {
|
|
|
cookiesEnabled: [
|
|
|
'bs.table.sortOrder', 'bs.table.sortName', 'bs.table.sortPriority',
|
|
|
'bs.table.pageNumber', 'bs.table.pageList',
|
|
|
- 'bs.table.hiddenColumns', 'bs.table.columns', 'bs.table.searchText',
|
|
|
+ 'bs.table.hiddenColumns', 'bs.table.searchText',
|
|
|
'bs.table.filterControl', 'bs.table.filterBy',
|
|
|
'bs.table.reorderColumns', 'bs.table.cardView', 'bs.table.customView'
|
|
|
],
|
|
|
@@ -208,7 +207,10 @@ Object.assign($.fn.bootstrapTable.utils, {
|
|
|
$.BootstrapTable = class extends $.BootstrapTable {
|
|
|
init () {
|
|
|
if (this.options.cookie) {
|
|
|
- if (this.options.cookieStorage === 'cookieStorage' && !UtilsCookie.isCookieSupportedByBrowser()) {
|
|
|
+ if (
|
|
|
+ this.options.cookieStorage === 'cookieStorage' &&
|
|
|
+ !UtilsCookie.isCookieSupportedByBrowser()
|
|
|
+ ) {
|
|
|
throw new Error('Cookies are not enabled in this browser.')
|
|
|
}
|
|
|
|
|
|
@@ -440,22 +442,8 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
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)
|
|
|
|
|
|
- if (typeof columnsCookieValue === 'boolean' && !columnsCookieValue) {
|
|
|
- throw new Error('The cookie value of filterBy must be a json!')
|
|
|
- }
|
|
|
-
|
|
|
- let columnsCookie = {}
|
|
|
-
|
|
|
- try {
|
|
|
- columnsCookie = JSON.parse(columnsCookieValue)
|
|
|
- } catch (e) {
|
|
|
- throw new Error('Could not parse the json of the columns cookie!', columnsCookieValue)
|
|
|
- }
|
|
|
-
|
|
|
let hiddenColumnsCookie = {}
|
|
|
|
|
|
try {
|
|
|
@@ -504,35 +492,12 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
|
|
|
if (hiddenColumnsCookie) {
|
|
|
for (const column of this.columns) {
|
|
|
- column.visible = !hiddenColumnsCookie.filter(columnField => {
|
|
|
- if (this.isSelectionColumn(column)) {
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- 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
|
|
|
}
|
|
|
|
|
|
- column.visible = columnsCookie.filter(columnField => {
|
|
|
- if (this.isSelectionColumn(column)) {
|
|
|
- return true
|
|
|
- }
|
|
|
- if (columnField instanceof Object) {
|
|
|
- return columnField.field === column.field
|
|
|
- }
|
|
|
-
|
|
|
- return columnField === column.field
|
|
|
- }).length > 0
|
|
|
+ column.visible = this.isSelectionColumn(column) ||
|
|
|
+ !hiddenColumnsCookie.includes(column.field)
|
|
|
}
|
|
|
}
|
|
|
}
|