Save state in Database

Save state in Database

kamilkamil Posts: 14Questions: 0Answers: 0
edited September 2011 in General
Hello, it is possible to save the state in a database? I only see a possibility to save the state in the cookie.
Thanks Kamil

Replies

  • kamilkamil Posts: 14Questions: 0Answers: 0
    Can anybody help me with this problem?
  • allanallan Posts: 63,400Questions: 1Answers: 10,451 Site admin
    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 .

    Allan
  • kamilkamil Posts: 14Questions: 0Answers: 0
    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.
  • allanallan Posts: 63,400Questions: 1Answers: 10,451 Site admin
    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.

    Allan
  • kamilkamil Posts: 14Questions: 0Answers: 0
    edited October 2011
    fnStateLoadCallback is undefined but why?
  • kamilkamil Posts: 14Questions: 0Answers: 0
    Is there another way to set the settings manually?
  • allanallan Posts: 63,400Questions: 1Answers: 10,451 Site admin
    > fnStateLoadCallback is undefined but why?

    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
  • kamilkamil Posts: 14Questions: 0Answers: 0
    edited October 2011
    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
  • kamilkamil Posts: 14Questions: 0Answers: 0
    edited October 2011
    no idea Allan or anybody??
  • kamilkamil Posts: 14Questions: 0Answers: 0
    Sorry for push but i have still the problem
  • kamilkamil Posts: 14Questions: 0Answers: 0
    push :)
  • kamilkamil Posts: 14Questions: 0Answers: 0
    despair :(
  • kamilkamil Posts: 14Questions: 0Answers: 0
    that´s my third post here and nobody can me help in anyone post.
This discussion has been closed.