Problem with multiple state cookies for a path

Problem with multiple state cookies for a path

martintroyemartintroye Posts: 3Questions: 0Answers: 0
edited February 2011 in General
When I have multiple pages in the same path using a data table we are seeing state cookies get deleted when another one is updated or added.

Here is an example of what I am seeing happen in FireFox using FireBug.

For a path of /Accounts/Invoice/ there is a New, Pend and Conflict page and each uses a data table. If I go to the New page and set the number of items per page the state cookie is written as SpryMedia_DataTables_InvoiceTable_new, when I switch to the Pend page the cookie SpryMedia_DataTables_InvoiceTable_pend is written, if I switch to the Conflict page the SpryMedia_DataTables_InvoiceTable_new cookie is deleted and SpryMedia_DataTables_InvoiceTable_conflict is added.

We are using version 1.7.4, any help would be most appreciated.

Replies

  • martintroyemartintroye Posts: 3Questions: 0Answers: 0
    edited February 2011
    I was able to get this working properly by using the fnCookieCallback to store the state data in a cookie with a custom name based on the page I am on. I have to set sCookiePrefix so that the internal name that is created matches my custom name when the cookie is read by _fnLoadState.

    [code]


    var _cookieName = "Page_New_DataTable_State";


    $(function () {
    /*start table code*/
    oTable = $('#InvoiceTable').dataTable({
    "sPaginationType": "full_numbers",
    "iDisplayLength": 10,
    "oLanguage": {
    "sLengthMenu": 'Display ' +
    '10' +
    '25' +
    '50' +
    '100' +
    'Show All' +
    ' items'
    },
    "sZeroRecords": "No work items found",
    "bAutoWidth": false,
    "bStateSave": true,
    "sCookiePrefix": _cookieName,
    "fnCookieCallback": function (sName, oData, sExpires, sPath) {
    var aParts = window.location.pathname.split('/');
    var sCookieName = _cookieName + "InvoiceTable" + '_' + aParts[aParts.length - 1].replace(/[\/:]/g, "").toLowerCase();
    return sCookieName + "=" + JSON.stringify(oData) + "; expires=" + sExpires + "; path=" + sPath;
    }
    });
    var oSettings = oTable.fnSettings();
    });


    [/code]
  • martintroyemartintroye Posts: 3Questions: 0Answers: 0
    Did some further testing and just setting the sCookiePrefix fixed the problem did not need to write the cookie out using fnCookieCallback.
This discussion has been closed.