Save DataTable states server side

This commit is contained in:
Bernd Bestel 2020-11-15 14:58:35 +01:00
parent 6866109b97
commit dd8fa5ff66
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 25 additions and 5 deletions

View File

@ -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)

View File

@ -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]);
}
});

View File

@ -503,7 +503,7 @@
<h5 id="qu-conversion-headline-info"
class="text-muted font-italic"></h5>
<table id="qu-conversions-table"
<table id="qu-conversions-table-products"
class="table table-sm table-striped nowrap w-100">
<thead>
<tr>