fnStateLoadCallback does not work in Datatables 1.8.2

fnStateLoadCallback does not work in Datatables 1.8.2

johnathanaujohnathanau Posts: 3Questions: 2Answers: 0
edited January 2015 in Free community support

I am working on a large codebase and we are using the old Datatable 1.8.2. We will not be updating any time soon.

My issue is that I am trying to override the fnStateSaveCallback and fnStateLoadCallback methods to persist state to server-side. On my page I have x amount of tables. I create the datatable with similar options like so:

$(document).ready(function() {
    $('#table').dataTable( {
        .....
        .....

        "bStateSave": true,
        "fnStateSaveCallback": function (oSettings, oData) {

            console.log("inside save");

            $.ajax({
                "url": "/url",
                "dataType": "json",
                "data": oData
            });
        },
        "fnStateLoadCallback": function (oSettings) {

            console.log("inside load");
            var o;

            $.ajax({
                "url": "/url",
                "dataType": "json",
                "success": function (json) {
                  o = json;
                }
            });

            return o;
        }
        .....
        .....
    } );
} );

It appears that fnStateSaveCallback gets called and something is printed in the console. However, fnStateLoadCallback never gets called. The only time it gets called is if I remove the fnStateSaveCallback, if I put the load function back in it fails again.

I don't understand what I am missing here.

When does fnStateLoadCallback get called? Moreover, why on earth does fnStateLoadCallback get called when I remove fnStateSaveCallback?

Answers

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    Sounds odd. You won't be surprised to learn that 1.8.2 is no longer supported outside of enterprise support, however a couple of points:

    1. You would need to make an synchronous call rather than an Async Ajax call since your function is returning undefined at the moment.
    2. Looking at the code in 1.8 it looks like the callback is only allow to manipulate the data object passed in as the second parameter. It doesn't care about the return value (other than a falsy value which stops the state loading.
    3. You'd need to add debug code to the old version to see why the load callback is only called when the save callback is not defined. I don't immediately see why that would be.

    Allan

  • johnathanaujohnathanau Posts: 3Questions: 2Answers: 0

    Hi Allan,

    Much appreciated for the work you have done on Datatables in general. Certainly has helped thousands.

    I decided to upgrade to version 1.9 instead and potentially 1.9.4.

This discussion has been closed.