You are correct - a cookie is the only built in option. Remember that DataTables is a client-side library - it has no knowledge of your server environment, nor should it.
Having said that, there are callback functions available which allow you to save the state to any location you wish, which you can then restore from that location in future. Have a look at http://datatables.net/usage/callbacks#fnStateSaveCallback .
Thanks Allen, but one problem i have. When i reload my table with oTable.fnReloadAjax() how i can set my new settings? they don´t passed fnStateLoadCallback whend i used fnReloadAjax only on first load.
You would need to read the information from your database and then set up the configuration options for the "saved object" (i.e. override the cookie) using fnStateLoadCallback. oData.iStart = 12; for example.
I have no idea I'm afraid. I would need to be able to see your code, and have the time, to be able to debug it. The example code from the documentation seems to work okay for me.
> Is there another way to set the settings manually?
Yes - you could pass them in using the initialisation options: http://datatables.net/ref (iDisplayLength for example).
Here is my Table
[code]
oTableDrucken = $('#table_drucken').dataTable({
"bServerSide": false,
"bProcessing": true,
"bLengthChange": false,
"bAutoWidth" : false,
"oColVis": {
"buttonText": "Zeige/Verstecke Spalten"
},
"sDom": 'r<"F"<"toolbar"RfC>>t<"F"i>',
"sAjaxSource": "includes/sites/json_data.php",
"fnServerData": function( sSource, aoData, fnCallback ) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
"fnInitComplete": function (sdata,responseData) {
init_TableTools(oTableDrucken,responseData["logo"]);
},
"aoColumns": [
/* 1 ID */ { "sClass": "name", "mDataProp": "id" , "sName": "id" },
/* 2 Name */ { "sClass": "name", "mDataProp": "name" , "sName": "name" },
],
"bStateSave": true,
"fnStateSaveCallback": function ( oSettings, sValue ) {
//Gives me the ColReorder Settings
var valueObj = $(oTableDrucken).dataTable().dataTableSettings[0].aoStateSave[1].fn(null,sValue)+"}";
dataTableSettings = $.parseJSON(valueObj);
return sValue;
},
"fnCookieCallback": function(sName, oData, sExpires, sPath) {
console.log("cookieCallback");
return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
},
"fnStateLoadCallback": function ( oSettings, oData ) {
oData.ColReorder = dataTableSettings.ColReorder;
oData.abVisCols = dataTableSettings.abVisCols;
return true;
},
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bSort": true,
"bInfo": true,
"oLanguage": oCustomLanguage("drucken")
});
[/code]
On first load there set the settings from my database.
Then i use on da button click only "oTableDrucken.fnReloadAjax();" and will set my new settings from Database
My problem is only to set the settings(ColReorder,abVisCols etc.) when i reload my table.
Thanks Kamil
Replies
Having said that, there are callback functions available which allow you to save the state to any location you wish, which you can then restore from that location in future. Have a look at http://datatables.net/usage/callbacks#fnStateSaveCallback .
Allan
Allan
I have no idea I'm afraid. I would need to be able to see your code, and have the time, to be able to debug it. The example code from the documentation seems to work okay for me.
> Is there another way to set the settings manually?
Yes - you could pass them in using the initialisation options: http://datatables.net/ref (iDisplayLength for example).
Allan
[code]
oTableDrucken = $('#table_drucken').dataTable({
"bServerSide": false,
"bProcessing": true,
"bLengthChange": false,
"bAutoWidth" : false,
"oColVis": {
"buttonText": "Zeige/Verstecke Spalten"
},
"sDom": 'r<"F"<"toolbar"RfC>>t<"F"i>',
"sAjaxSource": "includes/sites/json_data.php",
"fnServerData": function( sSource, aoData, fnCallback ) {
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
"fnInitComplete": function (sdata,responseData) {
init_TableTools(oTableDrucken,responseData["logo"]);
},
"aoColumns": [
/* 1 ID */ { "sClass": "name", "mDataProp": "id" , "sName": "id" },
/* 2 Name */ { "sClass": "name", "mDataProp": "name" , "sName": "name" },
],
"bStateSave": true,
"fnStateSaveCallback": function ( oSettings, sValue ) {
//Gives me the ColReorder Settings
var valueObj = $(oTableDrucken).dataTable().dataTableSettings[0].aoStateSave[1].fn(null,sValue)+"}";
dataTableSettings = $.parseJSON(valueObj);
return sValue;
},
"fnCookieCallback": function(sName, oData, sExpires, sPath) {
console.log("cookieCallback");
return sName + "="+JSON.stringify(oData)+"; expires=" + sExpires +"; path=" + sPath;
},
"fnStateLoadCallback": function ( oSettings, oData ) {
oData.ColReorder = dataTableSettings.ColReorder;
oData.abVisCols = dataTableSettings.abVisCols;
return true;
},
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bSort": true,
"bInfo": true,
"oLanguage": oCustomLanguage("drucken")
});
[/code]
On first load there set the settings from my database.
Then i use on da button click only "oTableDrucken.fnReloadAjax();" and will set my new settings from Database
My problem is only to set the settings(ColReorder,abVisCols etc.) when i reload my table.
Thanks Kamil