Only save displaylength state with cookies
Only save displaylength state with cookies
Hi,
with the option bStateSave:true the Datatables save the state (length, filtering, pagination and sorting) with a cookie (called SpryMedia_DataTables_etc..?).
Is it possible to save/store the actual iDisplayLength only? Only the value of the number of records in each page using pagination. In my project have not sense to store filters or pagination or sorting.
Thanks in advance.
Uri
DataTables is a GREAT plug-in for jQuery!
with the option bStateSave:true the Datatables save the state (length, filtering, pagination and sorting) with a cookie (called SpryMedia_DataTables_etc..?).
Is it possible to save/store the actual iDisplayLength only? Only the value of the number of records in each page using pagination. In my project have not sense to store filters or pagination or sorting.
Thanks in advance.
Uri
DataTables is a GREAT plug-in for jQuery!
This discussion has been closed.
Replies
I'm afraid that the bStateSave is "all or nothing". I hadn't actually considered the option of only making parts of the state saveable - it's an interesting idea.
It should be fairly easy to hack the core code to make it do what you are looking for if you wish. The functions _fnSaveState and _fnLoadState are the two in question. The easiest way would just be to comment out what you don't want in _fnLoadState. To optimise it a bit, you could modify _fnSaveState to only save the information you want.
Regards,
Allan
Hacking the core...uhmmm... it's too much for me! ;-)
Don't worry!if I try something, I will tell you.
Thanks again.
Uri
I am also interested in only saving the display length between sessions.
From what I can see in the code there has been no new options since 2009 and therefore I will go for the override _fnLoadState solution.
If possible future versions can have optional
* Page display
* Filter
* Sort
* Page (remember current page)
* Plugin
Best regards
Vilhelm Persson
Sorry, when trying to override the load function I noticed that there is now a callback function fnStateLoadCallback that will solve my needs.
Thanks
Vilhelm
var displayLength = $.cookie('the_cookie');
oDataTable = oTable.dataTable({
"bJQueryUI": true,
"iDisplayLength": displayLength == null ? 10 : displayLength,
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"sPaginationType": "full_numbers",
"sScrollY": "239px"
});
oContainer.find("select").change(function () {
$.cookie('the_cookie', oContainer.find("select").val(), { expires: 90 });
});
Allan
"bStateSave": true,
"fnStateLoadCallback": function ( oSettings, oData ) {
oData.sFilter = "";
oData.iStart=-1;
oData.iEnd=-1;
oData.aaSorting=oSettings.aaSorting;
delete oData.abVisCols;
delete oData.sFilterEsc;
delete oData.aaSearchCols;
return true;
}