stateSave gets ignored "sometimes"
stateSave gets ignored "sometimes"
Hi,
I got a strange behavior with stateSave option and I do not know how to debug it or find the problem or solution. Randomly my stateSave ignores the stateLoadCallback and I get the standard table settings saved.
inti the table:
stateSave: true,
stateSaveParams: function (settings, data) {
//Clear column search if there is any
for (var i = 0; i < data.columns.length; i++){
data.columns[i].search.search = "";
}
//Remove Search Value
data.search.search = "";
},
stateSaveCallback: function ( settings, data ) {
//Set html5 storage
localStorage.setItem( kind+'_table', JSON.stringify( data ) );
//Save to DB (User Login sets localStorage from DB)
table_db_save( kind+'_table', JSON.stringify( data ) );
},
stateLoadCallback: function ( settings ) {
//load saved settings from local storage
try {
return JSON.parse( localStorage.getItem( kind+'_table' ) );
} catch (e) {};
},
Does anyone else have this behavior? It happens in chrome & firefox on mac and also I got one customer complaining it wont save sometimes with windows and edge.
Is it possible to show an error message if the json string is wrong for datatables? Maybe there is a problem with the JSON format when i remove the values?
Live Version: www.btree.at/app
Login: demo_en@btree.at
PW: demo_en
It is in german but on the left side you see "Tabellen", there are multiple Datatables.
Cheers
Hannes
Answers
Ok seems I found a workaround at the moment, needs more testing but seems fine.
Cheers
Hannes