State Saving Problems

State Saving Problems

MargateSteveMargateSteve Posts: 5Questions: 0Answers: 0
edited July 2013 in General
Hi all.

I know that the problem I have is not unique to me but having tried all suggestions I can find on here (and Stackoverflow) I still cannot find a solution that works for me.

Simply, I want to be able to allow state saving on the tables but only for a limited period of time (probably 5 minutes after the last action) or until the browser is closed. The problem I am having is that the tables are already sorted on page load even in a browser that had not previously viewed that page.

Reading through various posts, I guessed that as there are several different tables on different pages, it may be that the state saved for one is being transferred to all others. Unfortunately, even after clearing the cache and all cookies (and restarting the browser to be sure) the tables still had their last sort state.

I initially thought that applying 'fnsavestate:false' or 'bsavestate:false' in-page may help but it is still the same. I have tried the suggestions at http://datatables.net/forums/discussion/8154/bstatesave-cookie-when-does-this-reset/p1 amongst others but nothing can clear the current state.

I cannot link to the pages as they are in an admin area and the code is a bit to paste in DataTables live but I have run the page through the debugger - http://debug.datatables.net/upasup


Can anyone please help with what I am trying to achieve............

Clear all the saved states that are currently on my tables (7 over 7 pages)

Implement one of the state saving options that will remember the sorting/filtering for 5 minutes after the last action or until the browser is closed.

Is it possibly to trigger a reset at will, ie from a button, that will automatically show the table as shown in the html?

I really do not mind if I use local storage or cookies at this point. This may be a show-stopper if I cannot get everything to reset but am sure that there must be a simple way that I cannot see.

Thanks
Steve

Replies

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    You've got the cookie duration set to 0 at the moment, try 1 (i.e. 1 second from now). You could also delete the cookie form the browser if you want to reset it completely. But I'm surprised that a new browser will load state - that sounds very odd.

    At the moment there isn't a method to clear the cookie at will, but it is a good idea to have that. I'll look at an API plug-in at some point.

    Allan
  • MargateSteveMargateSteve Posts: 5Questions: 0Answers: 0
    Thanks for the reply Allan.

    I have actually tried it with the cookie set to 30 seconds, left it for 2 minutes while I cleared every cookie (not just the ones relating to my site or Datables), cleared the cache and closed the browser.

    As soon as I started it back up, the state was still saved.

    When I get home tonight, unless I can get a chance to do it from my phone, I will remove the password protection from one of the pages and post the link here.

    Steve
  • MargateSteveMargateSteve Posts: 5Questions: 0Answers: 0
    A lesson to be learnt from looking with tired eyes! A fresh look this evening showed me that it was not actually saving the state but is actually automatically ascending on the first column.

    Aside from that, a 30 second cookie works correctly (overwriting the first column sort with the last state) so all I need to work out now is how to stop the first column auto sorting. And I am sure I have already seen that answer somewhere.
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    > all I need to work out now is how to stop the first column auto sorting

    Set aaSorting to be an empty array.

    Allan
  • MargateSteveMargateSteve Posts: 5Questions: 0Answers: 0
    Thanks Allan. I did actually find that last night and everything is working well. This is an awesome bit of kit!
This discussion has been closed.