bStateSave and multiple tables on a page
bStateSave and multiple tables on a page
doctorjw
Posts: 12Questions: 0Answers: 0
I'm using datatables 1.9.4 and have run into an interesting issue with bStateSave. We have a jsp which constructs a table; using bootstrap, we have a table on the page, and the data displayed alters based on the tab/link you click on. In playing with bStateSave in this situation, originally I had a single cookie, as expected, as the cookie name is only based on the page you are on, and the name of the table. I wanted to remember the state of the table based on which "tab" you are on, so I changed the naming of the table to reflect the tab. So instead of a single static name "itemTable", you'd see "itemTable_UNMAPPED_ITEMS", "itemTable_PRODUCTS", etc.
This seemed to work ... at first ... I'd enter a filter on the UNMAPPED_ITEMS tab, and then switch to other tabs, and back to UNMAPPED_ITEMS and the filtering was, indeed, remembered. If I switched to PRODUCTS and then entered a filter, though, my original UNMAPPED_ITEMS tab would lose it's remembered filtering.
In digging, I'm not seeing anything else like this. I did find this post:
http://www.datatables.net/forums/discussion/3997/problem-with-multiple-state-cookies-for-a-path/p1
which isn't quite the same situation, but similar. This pointed me to the use of "fnCookieCallback", so ... I grabbed the sample in the docs which should, I think, be an no-op:
[code]
"fnCookieCallback" : function( sName, oData, sExpires, sPath ) {
// Customise oData or sName or whatever else here
return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
}
[/code]
I really didn't expect anything to change, since this should set the cookie name and data just like the default, but ... it did. Suddenly, the behavior of the state saving worked perfectly.
I also tried setting the cookie prefix via "sCookiePrefix", without the fnCookieCallback, but the cookie naming didn't change.
For now, I'm good with a custom fnCookieCallback, but it's odd that this functions correctly while the default does not. Is there some issue with the default cookie setting where a situation like mine (mild difference in cookie name?) results in the old cookie being cleared?
Thanks,
john
This seemed to work ... at first ... I'd enter a filter on the UNMAPPED_ITEMS tab, and then switch to other tabs, and back to UNMAPPED_ITEMS and the filtering was, indeed, remembered. If I switched to PRODUCTS and then entered a filter, though, my original UNMAPPED_ITEMS tab would lose it's remembered filtering.
In digging, I'm not seeing anything else like this. I did find this post:
http://www.datatables.net/forums/discussion/3997/problem-with-multiple-state-cookies-for-a-path/p1
which isn't quite the same situation, but similar. This pointed me to the use of "fnCookieCallback", so ... I grabbed the sample in the docs which should, I think, be an no-op:
[code]
"fnCookieCallback" : function( sName, oData, sExpires, sPath ) {
// Customise oData or sName or whatever else here
return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
}
[/code]
I really didn't expect anything to change, since this should set the cookie name and data just like the default, but ... it did. Suddenly, the behavior of the state saving worked perfectly.
I also tried setting the cookie prefix via "sCookiePrefix", without the fnCookieCallback, but the cookie naming didn't change.
For now, I'm good with a custom fnCookieCallback, but it's odd that this functions correctly while the default does not. Is there some issue with the default cookie setting where a situation like mine (mild difference in cookie name?) results in the old cookie being cleared?
Thanks,
john
This discussion has been closed.
Replies
Allan
I can test with 1.10 beta, but it will be just a test --- this is supposed to go into production next week. It will take me a bit, as I need to pull in the new bootstrap 3 pagination (and rip out the stuff I originally plugged in). I'll let you know when I get the time to play with it.
Thanks! --- john