PDA

View Full Version : updatemanager: keepDataOnNoChange possible?



Wolfgang
25 Mar 2007, 6:54 AM
Hello,

is there something like "keepDataOnNoChange" implemented in updatemanager/datastore?
The idea: if the remote data (JSON or XML) has not changed, there is no need to update the datastore for a grid /view.

For example: The POST/GET request passed to the external dataprovider can contain some var(s) that help the external dataprovider to see if something has changed. If there is no change, the external provider would return a result like: "noChange" without any data.

This way, polling for new data would be cheaper than refreshing a grid/view with teh already existing data.

Animal
25 Mar 2007, 7:14 AM
You'd have to create your data providing servlet to be clever and return status 304 (Not Modified) if the data to be returned is the same as the last request from that session.

For UpdateManager, you could use a custom renderer:



function myRender : function(el, response, updateManager, callback){
if (response.status != 304) { // Only change the content if status is "Not Modified".
el.update(response.responseText, updateManager.loadScripts, callback);
}
}


For an HttpPproxy, you'd have to override the loadResponse method:



Ext.override(Ext.data.HttpProxy, {
loadResponse : function(o, success, response){
if(!success){
this.fireEvent("loadexception", this, o, response);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
var result;
if (response.status != 304) { // Only change the content if status is "Not Modified".
try {
result = o.reader.read(response);
this.lastResult = result;
}catch(e){
this.fireEvent("loadexception", this, o, response, e);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
} else {
result = this.lastResult; // use saved last result
}
o.request.callback.call(o.request.scope, result, o.request.arg, true);
}
});

Wolfgang
25 Mar 2007, 11:08 PM
Thank you animal.
I thought this idea would be a candidate for a feature request, but your solutions looks just fine.

Regards

Wolfgang