bStateSave cookies getting removed
bStateSave cookies getting removed
jeffreddy
Posts: 2Questions: 0Answers: 0
I'm not sure if this is a bug or by design but it's driving me crazy. I have 4 datatables on my site. I've set the "bStateSave" : true on each of them in order to remember the number of records to show.
I have found that when I set the number of rows to show to 100 for one of the datatables, it remembers that setting if I navigate away from the page and come back. I've also noted that a cookie is created named 'SpryMedia_DataTables_{tablename}_{pagename}.
When I navigate to another page with a datatable and then navigate away from it, a cookie is created for that datatable and page. This works until I've got 2 cookies cached and then I navigate away from a third page with a datatable. The first cookie created gets removed and only the 2nd and 3rd cookies remain.
There have been instances were there were 3 cookies created, but never all 4 as expected. The page names are all unique, but the table names are not. I'm not sure if that has any bearing or not.
Any help would be greatly appreciated.
I have found that when I set the number of rows to show to 100 for one of the datatables, it remembers that setting if I navigate away from the page and come back. I've also noted that a cookie is created named 'SpryMedia_DataTables_{tablename}_{pagename}.
When I navigate to another page with a datatable and then navigate away from it, a cookie is created for that datatable and page. This works until I've got 2 cookies cached and then I navigate away from a third page with a datatable. The first cookie created gets removed and only the 2nd and 3rd cookies remain.
There have been instances were there were 3 cookies created, but never all 4 as expected. The page names are all unique, but the table names are not. I'm not sure if that has any bearing or not.
Any help would be greatly appreciated.
This discussion has been closed.
Replies
In my DataTables setup, this looks like:
[code]
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
localStorage.setItem('dt-' + window.location.pathname, JSON.stringify(oData));
},
"fnStateLoad": function (oSettings) {
return JSON.parse(localStorage.getItem('dt-' + window.location.pathname));
}
[/code]
See: http://datatables.net/blog/localStorage_for_state_saving
If you want to stick with cookies, you might be able to solve this by setting CookiePrefix to something specific, though I haven't tried that (the cookies names are unique as is): http://datatables.net/ref#sCookiePrefix
Allan