Allow use of local storages instead of cookies

Allow use of local storages instead of cookies

piglettopigletto Posts: 1Questions: 0Answers: 0
edited November 2011 in Feature requests
Currently it is only possible to save state of datatables by using cookies. This has a drawback of creating big requests that sometimes also tend to cause '400 Bad request' errors (because of size).

I think it would be nice to allow users to choose (by some settings) whether they want to use cookies (customizable lifetime), local storage (indefinite lifetime) or session storage (session lenght lifetime).
Of course there has to be some feature detection involved in order to support older browsers (possibly with fallback to cookie), but in general, this shouldn't be hard to implement.

Replies

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Should actually be reasonably easy to implement I think. The state saving in DataTables just passes an object through to a cookie function, so it should just be an easy switch + the function to read/write local storage. Added to the to-do list!

    Thanks,
    Allan
  • John ArcherJohn Archer Posts: 56Questions: 1Answers: 0
    Hi!

    Any ideas when this feature will come? Due to the same problems as pigletto has/had I also need that. :-)

    I think about implementing it for my own as a kind of hack, which means loading the data from local storage, pass it to a cookie so DT can use it and after the table is completely initialized delete the cookie data.
    But I am not sure what drawbacks will arise when I implement so. Guess, pagination etc. good make trouble if the cookie is not there etc.

    So, a timeframe for that feature would be great! :-)

    Thanks a lot, Allan
  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    DataTables 1.9 and the functionality in the API for this is already implemented :-). Doing local storage itself for state saving will not be built into the DataTables core, but it will be very easy to do it with the API. I've been meaning to write a blog post for this exact topic, but just hasn't had the time yet. It will be done for the 1.9.0 beta 2 release, or shortly thereafter.

    Allan
  • John ArcherJohn Archer Posts: 56Questions: 1Answers: 0
    Man, this sounds really, really great! I absolutely don't mind that it is not included into the core, quite the contrary!

    As you might think, I am _very_ eager for beta 2 and the blog post now. even more than before. :-)

    Thanks a lot, mate!
This discussion has been closed.