Save form data offline
Save form data offline
in DataTables 2
Hello, I have a mobile application used on a tablet.
The internet connection frequently drops. Is there a way to temporarily save the form data and upload it to the server when an internet connection is established? Is this possible with DataTables Form? Ideally, I'd like the data to be saved every time the user leaves the form field. Thanks and regards, Chris
Answers
Hi Chris,
Have a look at this blog post which describes how you can save the changes locally and then have the user submit them in a batch with a button press.
Perhaps in your case you might want to go a step further, and instead of having a button to save changes, detect when the connection is up / down and when it comes back, if there are any changes, automatically submit them?
Allan
Hi Allan, thanks for the tip. I've now solved it with
localStorage.setItem("..")andval(localStorage.getItem..")for the form fields.But now the question is: How can I save an entire table like this? Can this also be done with
localStorage? Do you perhaps have an example?Thanks and regards, Chris
You can use
rows().data()to get the table data. ChaintoArray()to change the result to a standard Javascript array. Use JSON.stringify() to convert to a JSON string for local storage. Use JSON.parse() to reverse this when retrieving from local storage.Kevin