ajax and state saving
ajax and state saving
I've got an angularjs app that loads datatables when all content is loaded. works great. the source is ajax and i've got stateSave = true
.
What I'd like to see happen is: when I navigate to the page again (not refresh), I would expect the dataTables to not fetch the data from the server again, but use what it already has. Also, at the very least, I'd like the dataTables to save state. here are my issues:
- every time i navigate to the page, it fetches the data from the server
- i'm using stateSave = true
but this only works when i refresh the page. Shouldn't it work if i simply navigate away, then navigate back?
Wondering if anyone has seen this before. Am I not using stateSave
correctly? Or do AJAX source and stateSave not work like I thought it would?
Answers
each time you navigate to a page, its a fresh load. As such, it will go back to the server and get data. If you really need to prevent that from happening (though I cant imagine why), you can store data in the sessionStorage and retrieve it when the page loads
@bindrid The user experience is better. User comes to a list and waits a bit for the data to load, which is fine. I click an entry to view/edit that record. Save the record and return to the list. I have to wait for the list to repaint, and I lose my state (sort, filter, etc).
And actually, if I refresh the page, it does keep the state. But if I navigate away and come back, it does not keep it. The
stateSave
example on this site keeps the state, even when you navigate away. So I'm wondering what's happening.Any ideas?
It would be worth checking your table initialisation. Is it only being called once, with stateSave set to true?
Can you link to the page please? Every time you initialise the table, it will restore state if state saving is enabled and there is a state present.
The data in the table is not part of the state. If you are using
ajax
to get the data, then yes, it would always make a request to get the data when the table is initialised.Allan