Load/Save state ignoring pagination data

Load/Save state ignoring pagination data

lp22lp22 Posts: 2Questions: 1Answers: 0

I am noticing some bizarre behaviour when I am trying to save and load state in a simple client side application, I have some config like so:

const setState = (settings, data) => {
    const tableKey = `${stateKey}-${settings.sInstance}`;
    console.log(`saving state ${tableKey}`, data);
    localStorage.setItem(tableKey, JSON.stringify(data));
}

const getState = (settings) => {
    const tableKey = `${stateKey}-${settings.sInstance}`;
    const jsonString = localStorage.getItem(tableKey);
    const stateData = JSON.parse(jsonString);
    console.log(`loading state ${tableKey}`, stateData);
    return stateData;
}

const options = {
    stateSave: true,
    stateSaveCallback: setState,
    stateLoadCallback: getState,
    stateDuration: 0,
    // Other options
}

Where I am setting other options like enabling pagination, default ordering etc and that all works fine, then when the data table is initialized:

tableElement.DataTable(options);

I can see in the console that it is loading the state correctly, and start is down as lets say 30 but then immediately after it tries to save the page and the start is then 0.

Is there a reason why it saves immediately afterwards? one thing that I can say which may be causing it is that the data that drives the table is generated by knockout and the foreach binding may not have finished entirely by the time the table loads, but wanted to confirm if this is a known thing and if the lack of data on the table at setup time is what causes the issue.

Replies

  • allanallan Posts: 62,992Questions: 1Answers: 10,367 Site admin

    Are you doing a full draw, perhaps with a search term after initialisation? That is what would cause the paging to jump back to 0.

    Beyond that, I'd need a link to a test case showing the issue please.

    Allan

This discussion has been closed.