Local storage changes not reflecting

Local storage changes not reflecting

cuthbe123cuthbe123 Posts: 10Questions: 3Answers: 0

when we load the data table and then change the local storage settings, the table is not redrawing or showing the changes. What method do we need to call to make that work?

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @cuthbe123 ,

    The table only uses the stateSave configuration when it is initialised. If you change these values afterwards, you'll need to reinitialise the table.

    Hope that helps, if not, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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

  • cuthbe123cuthbe123 Posts: 10Questions: 3Answers: 0

    Okay so basically if I change the state underlying object I need to call $id.DataTable() again.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Yep, you'll need to destroy it first, as the table can't be reinitialised. Either add destroy to the initialisation, or call destroy() beforehand.

  • cuthbe123cuthbe123 Posts: 10Questions: 3Answers: 0

    Thanks so the destroy works but it takes out all of the css and everything. Thank you again for the suggestion. What I want to do is reload the column ordering after the table is initialised. Is there not an api to do that?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @cuthbe123 ,

    The destroy will take it out, but if you use it as the destroy, then it recreates the DataTable again, so the styling will be the same as it was.

    I'm not sure what you mean by reloading the column ordering after the initialisation. If you mean have a specific starting order, you can use order, if it it's something else, could you elaborate please.

    Cheers,

    Colin

  • cuthbe123cuthbe123 Posts: 10Questions: 3Answers: 0

    Hi Colin,

    Okay so using

    "destroy": true

    that creates the table and drop all styling and configuration. Basically what I want to do is hold the table state i.e column positions and width on my server. But my application loads the table on startup so it is already initialised.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @cuthbe123 ,

    stateSave doesn't hold any styling properties, like column positions and widths, it only saves column ordering, paging, searches, etc. If you want to include those, you'll need to add them yourself in stateSaveParams and stateLoadParams,

    Cheers,

    Colin

  • cuthbe123cuthbe123 Posts: 10Questions: 3Answers: 0
    edited May 2019

    Okay so you are saying I can call

    $('#example').dataTable( {
      "stateSave": true,
      "stateLoadParams": function (settings, data) {
        data.search.search = "";
      }
    } );
    

    so push the column layout events into an already initialised table? What is the method to get the column layout and sorting order?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    No, I'm saying the opposite :) The searches are included, the styling isn't. The problem you'll have is that the width, columns.width is an initialisation property and can't be changed post-initialisation, so you'll need to reinitialise the table with the new value.

This discussion has been closed.