State Saving

State Saving

bap22bap22 Posts: 5Questions: 3Answers: 0

Is there a way to save the state of the datatable across similar pages or a parent page?

For example, my app has a competitor page with a datatable. Each competitor has different data in the table, but the same table structure. State saving works for individual urls (such as /competitor/1234) but if I go to a different competitor such as /competitor/12345 the table is the default.

I am looking to save column order and hidden columns etc. by user logged in.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Yes. There was a discussion about this exactly topic not long ago and I provided an example of how it could be done, but I can't find it now!

    Because you simply would use stateSaveCallback and stateLoadCallback to store the information. If you look at the default methods you will be able to see that it uses the location.pathname parameter to add path information. You would just providing callbacks that don't use that information.

    Regards,
    Allan

  • bap22bap22 Posts: 5Questions: 3Answers: 0
    edited August 2014

    Perfect! This worked for me:

        stateSave:true,
        stateSaveCallback: function(settings, data){
            localStorage.setItem('competitorTable', JSON.stringify(data) );
        },
        stateLoadCallback: function(settings){
            return JSON.parse(localStorage.getItem('competitorTable') );
        },
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Nice one - thanks for sharing your solution with us!

    Allan

This discussion has been closed.