Load datatable state with old timestamp
Load datatable state with old timestamp
I want to have links to specific pages of datatable, with sorting and etc. I did this by saving state in hash:
window.DTapi = table.DataTable({
"stateSave": true,
"stateLoadCallback": function () {
if (location.hash) {
return JSON.parse(location.hash.replace('#', ''));
}
return undefined;
},
"stateSaveCallback": function (oSettings, oData) {
location.hash = JSON.stringify(oData);
}, ...
If I load state older than 1 hour, datatable reinitialize.
So, my questions are:
Is this a proper way to save links to datatable pages?
How to handle my timestamp problem?
Answers
Hey, it's been a long time since you open this post, but maybe someone is interested.
I'm saving different searchs to database so I can quickly load the state that i need from a dropdown.
I was having the same problem, the json have a time parameter (https://datatables.net/reference/option/stateSaveCallback) that stores the timestamp of when the state is created and if the time is too old the state will not load.
This is what I did:
In the stateLoadCallback function (https://datatables.net/reference/option/stateLoadCallback) of my datatables i change the time parameter in the success function:
"success": function (json) { json.time = Math.floor(Date.now()); o = json; }