State Saving does not work

State Saving does not work

visionxvisionx Posts: 22Questions: 4Answers: 5

I have a problem when I make a data table for state saving. I have configured "bStateSave=true" in data table and state has not been saved when I reload the page. I tried to save state in database using following way also but it did not work.

                "fnStateSave": function (oSettings, oData) {
                    alert('state saved...');
                // Send an Ajax request to the server with the state object
                    $.ajax( {
                        "url": '/testUrl/test.ajax?command=stateSave',
                        "data": oData,
                        "dataType": "json",
                        "method": "POST",
                        "success": function () {}
                    } );
                },

When this "fnStateSave" function is called? Is that happens each and every state change in data table such as sorting, pagination etc.?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin

    Can you show me your state load function please? The state saving looks okay and I presume is working?

    Allan

  • visionxvisionx Posts: 22Questions: 4Answers: 5

    This is the state load function.

    "fnStateLoad": function (oSettings, oData) {
    
        alert("state loaded");
        var o;
    
        $.ajax({
            type: "POST",
            url: "/testUrl/test.ajax?command=stateLoad",
            async: false,
        }).done(function(data) {
            o = $.parseJSON(data);
        });
    
        return o;
    },
    

    Even I am not seeing java script alert for the table state changes like sorting, paging etc. When this "fnStateSave" function is called...shouldnt it be called upon the each and every state change?

    Thanks in advance !!!

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    Answer ✓

    It should be, yes. Basically every draw will trigger a state change.

    Are you using 1.10? If so, use stateSaveCallback and stateLoadCallback rather than the old style parameter names. That might be the issue here.

    Allan

  • visionxvisionx Posts: 22Questions: 4Answers: 5
    edited February 2015

    Thanks a lot allan !!! I am using 1.10.4 version and when I use stateSaveCallback and stateLoadCallback functions it works as expected.

This discussion has been closed.