Apply loaded state to table

Apply loaded state to table

natemountainnatemountain Posts: 1Questions: 1Answers: 0

I am successfully saving my table's state with saveStateCallback and loading it with stateLoadCallback. However, the table is not reflecting the state loaded with stateLoadCallback.

I was looking at this question, and one of Allan's answers says that 'The state can only be loaded during initialisation'. How can I accomplish that? Am I understanding this correctly?

Here is the relevant code:

depot_table = $('#charger-overview-table-4').DataTable({
        "dom": 'ftipr',
        "sDom": "rtip",
        "pageLength": table_page_limit,
        "order": [[0, 'asc']],
        "columnDefs": [
            {type: 'any-number', targets: [1, 7]},
            {type: 'any-time', targets: [6]},
        ],
        stateSave: true,
        stateSaveParams: function(settings, data) {
            data.user = user;
            data.table_name = 'depot_table';
        },
        stateSaveCallback: function(settings, data) {
            $.ajax({
                url: sorting_url,
                data: data,
                dataType: "json",
                type: "GET",
                success: function() {}
            });
        },
        stateLoadCallback: function(settings, callback) {
            $.ajax({
                url: load_sorting_url,
                dataType: 'json',
                data: {user: user,
                       table_name: 'depot_table'},
                success: function(json) {
                    callback(json)
                }
            });
        },
        drawCallback: function () {
            $('[data-toggle="popover"]').popover({

                html: true,
                container: 'body',
                content: function () {
                    var content = $(this).attr("data-popover-content");
                    return $(content).children(".popover-body").html();
                },
                title: function () {
                    var title = $(this).attr("data-popover-content");
                    return $(title).children(".popover-heading").html();
                }
            });
        }
    });

Thanks!

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @natemountain ,

    That looks like it should work - the initialisation part Allan is referring to is how you're doing it, it just means during that table setup period. Would you be able to link to your page or create a test case that demonstrates it, so we can poke around. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.