diff --git a/changelog/60_UNRELEASED_2020-xx-xx.md b/changelog/60_UNRELEASED_2020-xx-xx.md index ec7e28c5..a80c6247 100644 --- a/changelog/60_UNRELEASED_2020-xx-xx.md +++ b/changelog/60_UNRELEASED_2020-xx-xx.md @@ -110,6 +110,7 @@ _- (Because the stock quantity unit is now the base for everything, it cannot be - Table columns can now be shown/hidden (new little eye icon on the top left corner on each table) - There are also new columns on some pages, hidden by default - Stock overview: Value, product group, calories +- Table states (visible columns, sorting, column order and so on) are now saved server side (in user settings) means that this stays the same when using different browsers - Dialogs are now used everywhere where appropriate instead of jumping between pages (for exampel when adding/editing shopping list items) - Added a "Clear filter"-button on all pages (with filters) to quickly reset applied filters - The data path (previously fixed to the `data` folder) is now configurable, making it possible to run multiple grocy instances from the same directory (with different `config.php` files / different database, etc.) (thanks @fgrsnau) diff --git a/public/js/grocy.js b/public/js/grocy.js index d03cbbe7..83bcb50a 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -698,13 +698,32 @@ $.extend(true, $.fn.dataTable.defaults, { }, 'stateSaveCallback': function(settings, data) { - // TODO: Save/load this server side - localStorage.setItem('datatables_state_' + settings.sTableId, JSON.stringify(data)); + var settingKey = 'datatables_state_' + settings.sTableId; + var stateData = JSON.stringify(data); + + Grocy.UserSettings[settingKey] = stateData; + + jsonData = {}; + jsonData.value = stateData; + Grocy.Api.Put('user/settings/' + settingKey, jsonData, + function(result) + { + // Nothing to do... + }, + function(xhr) + { + if (!xhr.statusText.isEmpty()) + { + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) + } + } + ); }, 'stateLoadCallback': function(settings, data) { - // TODO: Save/load this server side - return JSON.parse(localStorage.getItem('datatables_state_' + settings.sTableId)); + var settingKey = 'datatables_state_' + settings.sTableId; + + return JSON.parse(Grocy.UserSettings[settingKey]); } }); diff --git a/views/productform.blade.php b/views/productform.blade.php index 7fe75c32..08ab3f2f 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -503,7 +503,7 @@
-