Commit f3a4c916 authored by Romain Loth's avatar Romain Loth

[FIX] terms table: cache for sort preferences too

parent 1a0a6737
...@@ -198,6 +198,11 @@ function saveParamsToCache() { ...@@ -198,6 +198,11 @@ function saveParamsToCache() {
// var page_status = document.getElementsByClassName("dynatable-page-link dynatable-active-page")[0].getAttribute("data-dynatable-page") // var page_status = document.getElementsByClassName("dynatable-page-link dynatable-active-page")[0].getAttribute("data-dynatable-page")
var per_page_status = MyTable.data('dynatable').settings.dataset.perPage var per_page_status = MyTable.data('dynatable').settings.dataset.perPage
// ex: {'name':1} or {'score':-1}
var sorting_obj = MyTable.data('dynatable').settings.dataset.sorts
var sort_type_status = Object.keys(sorting_obj).pop()
var sort_direction_status = sorting_obj[sort_type_status]
// keys and values are str only so we use path-like keys // keys and values are str only so we use path-like keys
if (search_filter_status) { if (search_filter_status) {
localStorage[corpusId+'/terms/search'] = search_filter_status localStorage[corpusId+'/terms/search'] = search_filter_status
...@@ -207,9 +212,11 @@ function saveParamsToCache() { ...@@ -207,9 +212,11 @@ function saveParamsToCache() {
} }
if (state_filter_status) { if (state_filter_status) {
// console.warn("state_filter_status is set")
localStorage[corpusId+'/terms/state'] = state_filter_status localStorage[corpusId+'/terms/state'] = state_filter_status
} }
else { else {
// console.warn("state_filter_status is NOT set")
localStorage.removeItem(corpusId+'/terms/state') localStorage.removeItem(corpusId+'/terms/state')
} }
if (type_filter_status) { if (type_filter_status) {
...@@ -219,19 +226,11 @@ function saveParamsToCache() { ...@@ -219,19 +226,11 @@ function saveParamsToCache() {
localStorage.removeItem(corpusId+'/terms/type') localStorage.removeItem(corpusId+'/terms/type')
} }
// if (page_status) { localStorage[corpusId+'/terms/perPage'] = per_page_status
// localStorage[corpusId+'/terms/page'] = page_status // localStorage[corpusId+'/terms/page'] = page_status
// }
// else {
// localStorage.removeItem(corpusId+'/terms/page')
// }
if (per_page_status) { localStorage[corpusId+'/terms/sortType'] = sort_type_status
localStorage[corpusId+'/terms/perPage'] = per_page_status localStorage[corpusId+'/terms/sortDirection'] = sort_direction_status
}
else {
localStorage.removeItem(corpusId+'/terms/perPage')
}
return null; return null;
} }
...@@ -244,6 +243,8 @@ function restoreSettingsFromCache() { ...@@ -244,6 +243,8 @@ function restoreSettingsFromCache() {
var had_state = localStorage[corpusId+'/terms/state'] var had_state = localStorage[corpusId+'/terms/state']
var had_search = localStorage[corpusId+'/terms/search'] var had_search = localStorage[corpusId+'/terms/search']
var had_perPage = localStorage[corpusId+'/terms/perPage'] var had_perPage = localStorage[corpusId+'/terms/perPage']
var had_sortType = localStorage[corpusId+'/terms/sortType']
var sortDirection = localStorage[corpusId+'/terms/sortDirection']
// if (had_page) { // if (had_page) {
// MyTable.data('dynatable').paginationPage.set(had_page); // MyTable.data('dynatable').paginationPage.set(had_page);
// } // }
...@@ -259,6 +260,11 @@ function restoreSettingsFromCache() { ...@@ -259,6 +260,11 @@ function restoreSettingsFromCache() {
if (had_perPage) { if (had_perPage) {
MyTable.data('dynatable').paginationPerPage.set(had_perPage) MyTable.data('dynatable').paginationPerPage.set(had_perPage)
} }
if (had_sortType) {
MyTable.data('dynatable').sorts.clear();
MyTable.data('dynatable').sorts.add(had_sortType, sortDirection)
console.log("added sort",had_sortType)
}
// re-process to makes the changes visible // re-process to makes the changes visible
MyTable.data('dynatable').process() MyTable.data('dynatable').process()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment