bStateSave cookies getting removed

bStateSave cookies getting removed

jeffreddyjeffreddy Posts: 2Questions: 0Answers: 0
edited August 2012 in Bug reports
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.

Replies

  • semenkosemenko Posts: 2Questions: 0Answers: 0
    FWIW, I'm also having this problems. Four pages (with different filenames, e.g. a.html, b.html), all with paginated datatables, and "bStateSave" cookies seem to constantly disappear.
  • semenkosemenko Posts: 2Questions: 0Answers: 0
    I've worked around this by using LocalStorage and setting specific storage entry names.

    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
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    The usual problem with cookies is that you only get 4K of space to storage information. Depending on how many columns you have, that's really not very much. localStorage is the way forward here, and I might make it the default in v1.10.

    Allan
This discussion has been closed.