Loading state works, unless state hasn't been saved yet

Loading state works, unless state hasn't been saved yet

nesadinesadi Posts: 2Questions: 1Answers: 0

Been trying to figure this out for a week and I'm at my wit's end. I changed a table to save and load its state through AJAX, but if I start from a new session and the state hasn't been saved yet (so that there's nothing to load), then the table doesn't load at all (no table shows up on the page). How do I get it to ignore the retrieved Json data (which is {} anyway)? These are the relevant parts of my table. The stateLoadParams part was my latest attempt that failed.

        stateSave: true,
        stateSaveCallback: function (settings, data) {
            $.ajax( {
                url: "{% url 'finder:save_datatable' %}",
                data: JSON.stringify(data),
                dataType: "json",
                type: "POST",
                success: function () {},
            });
        },
        "stateLoadParams": function (settings, data) {
            if (Object.entries(data).length === 0 && data.constructor === Object) {
                return false;
            }
        },
        stateLoadCallback: function (settings, callback) {
            $.ajax( {
                url: '{% url "finder:load_datatable" %}',
                dataType: 'json',
                success: function (data) {
                    json = JSON.parse(data);
                    callback( json  );
                },
            });
        },

Answers

This discussion has been closed.