Prevent datatables from creating cookies

Prevent datatables from creating cookies

ntzavellasntzavellas Posts: 4Questions: 1Answers: 0

Hello
When the users of my app view a datatable with a data-hidden column, a cookie is been created.

The problem is that I have datatables in bootstrap modals often used. This results in the creation of many cookies which result in an error 400 on every post.

I did some reading on how and why datatables use cookies and tried to prevent (or use session or localstorage instead of cookies) that functionality because I do not really need it but no luck.

No matter what, when the browser is minimized to hide columns, a cookie is created.

I also tried setting the cookie duration to 10 seconds so this problem will not occur but still no luck.

I use datatables.responsive.js version 0.2.0 and datatables version 1.10.2

This is a sample code I use to try and prevent cookie creation:

$('#tblId').dataTable({
"stateSave": true,
"stateSaveCallback": function (oSettings, oData) {
localStorage.setItem('DataTables_' + window.location.pathname, JSON.stringify(oData));
},
"stateLoadCallback": function (oSettings) {
return JSON.parse(localStorage.getItem('DataTables_' + window.location.pathname));
},
"iCookieDuration": 10,
"bFilter": false,
"bDestroy": true,
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{ "sType": "globalized-date", "aTargets": [1] },
{ "sType": "currency", "aTargets": [7] }
]
});
$('#tblId').fnSort([[1, 'desc']]);

Answers

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    DataTables 1.10+ does not create cookies. There is no code in the library to do so. You might be using 1.9- which does create cookies, but without a link to a test case (as required in the forum rules) I can't really offer any further help I'm afraid.

    Allan

  • ntzavellasntzavellas Posts: 4Questions: 1Answers: 0

    Hello Allan

    Unfortunately the app is a cms system in which I can not grand access. I tried using jsfiddle but it creates a bucnh of cookies on its own.

    This is the cookie created on the page in case you can suggest any solytions:

    Name: DataTablesResponsiveHelper_tableSearchResults_transactions
    Content: %7B%22columnIndexes%22%3A%5B0%2C1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%5D%2C%22columnsHiddenIndexes%22%3A%5B3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%5D%2C%22breakpoints%22%3A%7B%22phone%22%3A%7B%22name%22%3A%22phone%22%2C%22upperLimit%22%3A480%2C%22columnsToHide%22%3A%5B1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%5D%2C%22lowerLimit%22%3A0%7D%2C%22tablet%22%3A%7B%22name%22%3A%22tablet%22%2C%22upperLimit%22%3A1424%2C%22columnsToHide%22%3A%5B3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%5D%2C%22lowerLimit%22%3A480%7D%2C%22always%22%3A%7B%22name%22%3A%22always%22%2C%22lowerLimit%22%3A1424%2C%22upperLimit%22%3Anull%2C%22columnsToHide%22%3A%5B%5D%7D%7D%2C%22expandColumn%22%3A0%2C%22lastBreakpoint%22%3A%22tablet%22%7D
    Domain: localhost
    Path: /
    Send for: Any kind of connection
    Accessible to script: Yes
    Created: Tuesday, March 17, 2015 at 12:20:34 AM
    Expires: Tuesday, March 17, 2015 at 2:20:34 PM

  • ntzavellasntzavellas Posts: 4Questions: 1Answers: 0

    As you can see the cookie duration is 2 hours and not 10 seconds (set in datatable init options). The same cookie is created if i 'leave out' the stateSave, stateSaveCallback and stateLoadCallback...

    any suggestion is welcome

    thank you

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    That isn't a cookie that the Responsive extension creates. Indeed responsive doesn't even have the text "Helper" anywhere in it.

    Are you using some other extension? Can you link to the page please.

    Allan

  • ntzavellasntzavellas Posts: 4Questions: 1Answers: 0

    Thanks for the quick response allan.

    You are right, we are using a different responsive extention (https://github.com/Comanche/datatables-responsive).

    We will change it to //cdn.datatables.net/responsive/1.0.4/js/dataTables.responsive.js and hopefully the problem will be fixed.

This discussion has been closed.