This is a migrated thread and some comments may be shown as answers.

Datasouce Read from server rather than cache when the user pulls to refresh

2 Answers 15 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
eaigs
Top achievements
Rank 1
eaigs asked on 15 Oct 2013, 10:41 AM
Hi,
We have the following datasource
var messages = new kendo.data.DataSource({
    transport: {
        read: function(operation) {
            var cachedData = localStorage.getItem("cachedMessages");
            if (cachedData != null || cachedData != undefined) {
                operation.success(JSON.parse(cachedData));
            }
            else {
                operation.success(getMessages());
            }                
        }
    }       
});
I only want it to hit the server "getMessagesFromServer()" if there is no cache (which is working) or when the user "pulls to refresh" in the listview e.g.
<ul id="messages-list-view" data-role="listview" data-source="messages" data-template="message-template" data-pull-to-refresh="true">
</ul>
How can I tell messages.read that the user has forced a refresh and it needs to go to the server to get the data rather than the cache.

Thanks in advance

Eaigs

2 Answers, 1 is accepted

Sort by
0
eaigs
Top achievements
Rank 1
answered on 17 Oct 2013, 08:56 AM
var messages = new kendo.data.DataSource({
    data: cachedMessages,
    transport: {
        read: function(operation) {
}});
Seems to do the trick
0
Thomas
Top achievements
Rank 1
answered on 07 Feb 2014, 04:17 PM
ASG, I'm looking to do the exact same thing and having troubles implementing it like you mention.  Could you post some more details on what you did?

What is in getMessages() ?
Tags
Data Source
Asked by
eaigs
Top achievements
Rank 1
Answers by
eaigs
Top achievements
Rank 1
Thomas
Top achievements
Rank 1
Share this question
or