_fnLoadState doesn't respect own cookie name
_fnLoadState doesn't respect own cookie name
boecko
Posts: 9Questions: 0Answers: 0
I'd like to implement a global TableState for one kind of table, which can be inserted in the page multiple times (so same id is a nogo).
fnCookieCallback allows me to customize the name for saving, but loadState falls back to
[code]fnReadCookie( oSettings.sCookiePrefix+oSettings.sInstance ); [/code]
fnCookieCallback allows me to customize the name for saving, but loadState falls back to
[code]fnReadCookie( oSettings.sCookiePrefix+oSettings.sInstance ); [/code]
This discussion has been closed.
Replies
_fnLoadState should report back, if the cookie is already set.
e.g. oInit.bCookieSet = true.
This is helpful, if you want to set some default-filters at the first run.
[code]
var opts = { bSaveState : true };
var oTable = $(el).dataTable(opts);
if(!opts.bCookieSet) {
// code to apply default advanced filter
}
else {
// code to set the advanced filter-checkbox to the saved State
}
[/code]
For the cookie name - that is an extremely good point... I'm not certain of the best way of handling that just yet - perhaps an override parameter, or also a callback function. I'll have a think!
Thanks,
Allan
Here's the patch
[code]
--- /Users/aboe/Downloads/2010-10-20/DataTables-1.7.3/media/js/jquery.dataTables.js 2010-09-30 22:55:20.000000000 +0200
+++ jquery.dataTables.js 2010-10-20 15:35:36.000000000 +0200
@@ -1223,6 +1223,7 @@
* Scope: jQuery.dataTable.classSettings
*/
this.sCookiePrefix = "SpryMedia_DataTables_";
+ this.sCookieName = null;
/*
* Variable: fnCookieCallback
@@ -5791,7 +5792,8 @@
sValue += "}";
- _fnCreateCookie( oSettings.sCookiePrefix+oSettings.sInstance, sValue,
+ var sCookieName = oSettings.sCookieName || oSettings.sCookiePrefix+oSettings.sInstance;
+ _fnCreateCookie(sCookieName, sValue,
oSettings.iCookieDuration, oSettings.sCookiePrefix, oSettings.fnCookieCallback );
}
@@ -5810,9 +5812,11 @@
}
var oData;
- var sData = _fnReadCookie( oSettings.sCookiePrefix+oSettings.sInstance );
+ var sCookieName = oSettings.sCookieName || oSettings.sCookiePrefix+oSettings.sInstance;
+ var sData = _fnReadCookie( sCookieName );
if ( sData !== null && sData !== '' )
{
+ oInit.bCookieSet = true;
/* Try/catch the JSON eval - if it is bad then we ignore it - note that 1.7.0 and before
* incorrectly used single quotes for some strings - hence the replace below
*/
@@ -6362,6 +6366,7 @@
_fnMap( oSettings, oInit, "sAjaxSource" );
_fnMap( oSettings, oInit, "iCookieDuration" );
_fnMap( oSettings, oInit, "sCookiePrefix" );
+ _fnMap( oSettings, oInit, "sCookieName" );
_fnMap( oSettings, oInit, "sDom" );
_fnMap( oSettings, oInit, "oSearch", "oPreviousSearch" );
_fnMap( oSettings, oInit, "aoSearchCols", "aoPreSearchCols" );
[/code]