Skip to content

Commit

Permalink
fixes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
aocneanu committed Mar 13, 2018
1 parent 0e83ef2 commit 5769158
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/resources/assets/js/components/enso/vuedatatable/VueTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,26 @@ export default {
},
setPreferences() {
this.setDefaultPreferences();
if (localStorage.getItem(this.preferencesKey) !== null) {
this.setUserPreferences();
}
this.checkSavedPreferences();
this.$nextTick(() => {
this.initialised = true;
});
},
checkSavedPreferences() {
if (localStorage.getItem(this.preferencesKey) === null) {
return;
}
const prefs = JSON.parse(localStorage.getItem(this.preferencesKey));
if (prefs.columns.length !== this.template.columns.length) {
localStorage.removeItem(this.preferencesKey);
return;
}
this.setUserPreferences(prefs);
},
setDefaultPreferences() {
this.template.columns.forEach(({ meta }) => {
this.$set(meta, 'sort', null);
Expand All @@ -259,15 +270,15 @@ export default {
this.$set(this.template, 'sort', false);
},
setUserPreferences() {
const prefs = JSON.parse(localStorage.getItem(this.preferencesKey));
setUserPreferences(prefs) {
Object.keys(prefs.global).forEach((key) => {
this.$set(this, key, prefs.global[key]);
});
Object.keys(prefs.template).forEach((key) => {
this.$set(this.template, key, prefs.template[key]);
if (this.template[key] !== undefined) {
this.$set(this.template, key, prefs.template[key]);
}
});
prefs.columns.forEach((column, index) => {
Expand Down

0 comments on commit 5769158

Please sign in to comment.