bStateSave cookie: when does this reset?
bStateSave cookie: when does this reset?
aluferrari
Posts: 22Questions: 1Answers: 0
Hi,
We have a problem regarding bStateSave cookie. We have used bStateSave=true. The feature is working fine, but it works a little too much.
It remembers the state even after the user logs out of the application. So the next time when user again visits the page, the settings are still there.
Q1. When does the cookie gets deleted/reset?
Q2. Is there a way to manually delete/reset the cookie?
Thanks a lot in advance.
- Aalap
We have a problem regarding bStateSave cookie. We have used bStateSave=true. The feature is working fine, but it works a little too much.
It remembers the state even after the user logs out of the application. So the next time when user again visits the page, the settings are still there.
Q1. When does the cookie gets deleted/reset?
Q2. Is there a way to manually delete/reset the cookie?
Thanks a lot in advance.
- Aalap
This discussion has been closed.
Replies
When the cookie expires. That is controlled by iCookieDuration .
> Q2. Is there a way to manually delete/reset the cookie?
Not really - you could work out the name of the cookie and delete it I suppose. Or your could stop the saved state from loading, but if you want a session only cookie, then you would either need to modify the DataTables core, or look at writing your own method to do the state storage. This blog post might interest you: http://datatables.net/blog/localStorage_for_state_saving
Allan
We are looking for a way to keep the state saved till active session only or may be till the window is closed.
Please help.
Thank you.
- Aalap
Allan
Cheers!
[code]
function save_dt_view (oSettings, oData) {
localStorage.setItem( 'DataTables_'+window.location.pathname, JSON.stringify(oData) );
}
function load_dt_view (oSettings) {
return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname) );
}
function reset_dt_view() {
localStorage.removeItem('DataTables_'+window.location.pathname);
}
[/code]
so my tables are loaded with
[code]
...
"bStateSave": true,
"fnStateSave": function(oSettings, oData) { save_dt_view(oSettings, oData); },
"fnStateLoad": function(oSettings) { return load_dt_view(oSettings); },
...
[/code]
and then I just hook the reset function to a button on the page just below the table which deletes the settings and refreshes the page. all done.
[code]
"fnStateSave": function ( oSettings, oData ) {
localStorage.setItem( 'DataTables'
+ window.location.pathname
+ '<%=Session.SessionID.Substring(1,3)%>',
JSON.stringify( oData ) );
},
"fnStateLoad": function ( oSettings ) {
return JSON.parse( localStorage.getItem( 'DataTables'
+ window.location.pathname
+ '<%=Session.SessionID.Substring(1,3)%>' ) );
}
[/code]
The window.location.pathname makes sure that multiple tables on differing pages use only their settings and the appended chunk of Session ID makes sure the storage is only read for the current session, unless of course the user manages to get the exact same chunk as before.
Another note: I have not yet looked into the implications of creating a new, local, file every time the user starts a new session. Does the browser delete it on its own or will this cause files to build up overtime?
EDIT: After a quick test in Chrome the local storage files pile up as the session changes. So do this at your own risk!