iLenght in cookie who's not used on refresh

iLenght in cookie who's not used on refresh

moufmouf Posts: 4Questions: 0Answers: 0
edited September 2011 in General
Hi,

First of all thank you for your amazing plugin !
However, i ve got a problem with the ilenght cookie param :

here is my code :
[code]


var oTable = $('#'+tbl_name).dataTable( $.extend( true, {}, oDTDefault, {
"sAjaxSource": site_url+controller+'/json_liste',
"sDom": '<"lst_top"rp<"lst_add '+prefix+'lst_add">f<"lst_filter '+prefix+'lst_filter">Tl>t<"lst_bottom"pi>',
"aoColumnDefs":[
{ "bSortable": false, "aTargets": [ 1 ] },
{ "bSortable": false, "aTargets": [ 2 ] },
{ "bSortable": false, "sClass": "center", "aTargets": [ 3 ] }
],
"fnCookieCallback": function (sName, oData, sExpires, sPath) {
/* Customise oData or sName or whatever else here */
return tbl_name + "="+encodeURIComponent(JSON.stringify(oData))+"; expires=" + sExpires +"; path=" + sPath;
},
"fnInitComplete": function(oSettings, json) {
$('.'+prefix+'lst_add').html('');
$('.'+prefix+'lst_filter').html('Afficher les filtres');
},
"fnServerParams": function(aoData) {
aoData.push({ "name": "gid", "value": $('#'+prefix+'gid').val() });
aoData.push({ "name": "cid", "value": id_client });
aoData.push({ "name": "uid", "value": $('#'+prefix+'uid').val() });
aoData.push({ "name": "statut", "value": $('#'+prefix+'statut').val() });
},
"fnStateSaveCallback": function ( oSettings, sValue ) {
sValue += ',"uid": "'+$('select#'+prefix+'uid').val()+'"';
sValue += ',"statut": "'+$('select#'+prefix+'statut').val()+'"';
sValue += ',"gid": "'+$('select#'+prefix+'gid').val()+'"';
if(id_client != '') sValue += ',"cid": "'+$('select#'+prefix+'cid').val()+'"';

return sValue;
}
}));
[/code]

as you can see, i'm adding some parameters in the cookie wich works well, ex i'm filtering by id user (uid) data is well recorded and if i m reloading the page my filter is correctly loaded, so why the iLength value isn't recognize ? in my cookie i can see it when i change the filter, here we can see iLength:50

[quote]
%7B%22iCreate%22%3A1316951166276%2C%22iStart%22%3A0%2C%22iEnd%22%3A0%2C%22iLength%22%3A50%2C%22sFilter%22%3A%22%22%2C%22sFilterEsc%22%3Atrue%2C%22aaSorting%22%3A%5B%5B1%2C%22asc%22%5D%5D%2C%22aaSearchCols%22%3A%5B%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%5D%2C%22abVisCols%22%3A%5Btrue%2Ctrue%2Ctrue%2Ctrue%5D%2C%22uid%22%3A%224%22%2C%22statut%22%3A%22%22%2C%22gid%22%3A%22%22%7D
[/quote]

So why when i'm reloading i can see in the firebug console that the iLenght value reset to 10 ? do i have to add these value in the fnServerParams ?

Thank you by advance !


[edit] of course i use 1.8.2 !
It appears that all default parameters are not loaded like sFilter, pagination and of course iLenght.
TRied so many things like ajax call (more often used in your example using fndataServer).
Plz help !
the trouble is here but dont know why

[code]

"fnCookieCallback": function (sName, oData, sExpires, sPath) {
return tbl_name + "="+encodeURIComponent(JSON.stringify(oData))+"; expires=" + sExpires +"; path=" + sPath;
},
[/code]

if i comment this datatables use his correct params but not mine

[/edit]

Replies

  • moufmouf Posts: 4Questions: 0Answers: 0
    Up !
    Really need help, am i doing something wrong ?
  • moufmouf Posts: 4Questions: 0Answers: 0
    Ok i've found that the trouble is in cookie naming.
    For info i use codeigniter wich make url as : projet/index.php/user/detail/?sc_id=3107

    my table id :
    $tbl_name = PREFIX_SOCIETE.'tbl';
    so, to acces to my params i use :
    [code]

    var default_select_uid, default_select_gid, default_select_statut = '';
    var dtCookie = $.parseJSON( $.cookie(tbl_name) );
    if(dtCookie && (dtCookie.uid || dtCookie.gid || dtCookie.statut)) {
    if(dtCookie.uid) default_select_uid = dtCookie.uid;
    if(dtCookie.gid) default_select_gid = dtCookie.gid;
    if(dtCookie.statut) default_select_statut = dtCookie.statut;

    $('.'+prefix+'tbl_filter').show();
    }
    [/code]

    this works fine.

    but it seems that the datatables cookiereading function is not ok with this format.

    So with default cookie format (just changing the prefix)
    if i m here : url:projet/index.php/societe my cookie name is : wan_sc_tbl_societe who seems ok
    but if i'm here : url: projet/societe/home_detail/ cookie name is wan_sc_tbl_ which is wrong it should be wan_sc_tbl_societe_home_detail
  • moufmouf Posts: 4Questions: 0Answers: 0
    ok i solved my probleme due ton inexperience, so maybe it would help another one

    [code]
    $tbl_name = PREFIX_SOCIETE.'tbl'.str_replace('/', '', $this->uri->uri_string());

    external cookie data
    var default_select_uid, default_select_gid, default_select_statut = '';
    var dtCookie = $.parseJSON( $.cookie('datatable prfix_'+tbl_name+'_') );
    if(dtCookie && (dtCookie.uid || dtCookie.gid || dtCookie.statut)) {
    if(dtCookie.uid) default_select_uid = dtCookie.uid;
    if(dtCookie.gid) default_select_gid = dtCookie.gid;
    if(dtCookie.statut) default_select_statut = dtCookie.statut;

    $('.'+prefix+'tbl_filter').show();
    }
    [/code]

    .. and that all, so i dont need this
    [code]

    "fnCookieCallback": function (sName, oData, sExpires, sPath) {
    return sName + "="+encodeURIComponent(JSON.stringify(oData))+"; expires=" + sExpires +"; path=" + sPath;
    }
    [/code]
This discussion has been closed.