PDA

View Full Version : Overridding Store's Remote Sort behavior



locutusUT
25 Nov 2009, 10:44 AM
The service I'm calling has the ability to sort but it combines it into one HTTP parameter called sort, rather than sort/dir as per the ExtJS implementation. I've attempted to override this by concatenating the two fields on "beforeload" in the code below. This, however, will not load my data.

Is there something flawed in my approach?



Ext.override(Ext.data.Store, {
load : function(options){
options = options || {};
if(this.fireEvent("beforeload", this, options) !== false){
this.storeOptions(options);
var p = Ext.apply(options.params || {}, this.baseParams);
if(this.sortInfo && this.remoteSort){
var pn = this.paramNames;
p[pn["sort"]] = this.sortInfo.field + ' ' + this.sortInfo.direction.toLowerCase();
// p[pn["dir"]] = this.sortInfo.direction;
}
this.proxy.load(p, this.reader, this.loadRecords, this, options);
return true;
} else {
return false;
}
}
});

Fredric Berling
26 Nov 2009, 4:03 AM
Dont know about your code, but this is a working override for Ext 3.0.0 public release


Ext.override(Ext.data.Store, {
load : function(options) {
options = options || {};
this.storeOptions(options);
if(this.sortInfo && this.remoteSort){
var pn = this.paramNames;
options.params = options.params || {};
options.params[pn.sort] = this.sortInfo.field + ' ' + this.sortInfo.direction.toLowerCase();
//options.params[pn.dir] = this.sortInfo.direction;
}
try {
return this.execute('read', null, options); // <-- null represents rs. No rs for load actions.
} catch(e) {
this.handleException(e);
return false;
}
}
});

Condor
26 Nov 2009, 5:44 AM
Why are you overriding the store load method when you can do the same with a simple beforeload event handler?

store.on('beforeload', function(store, options){
var pn = store.paramNames;
options.params[pn.sort] = options.params[pn.sort] + ' ' + options.params[pn.dir].toLowerCase();
delete options.params[pn.dir];
});

(assuming you are using Ext 3.x, because the override you posted is based on Ext 2.x)

locutusUT
26 Nov 2009, 8:44 AM
Thanks guys! remoteSort is working for me now as expected.

Mike Robinson
1 Dec 2009, 8:46 AM
Faced with a similar requirement, I went one step further and defined a "company-specific" descendant class for use in "our" applications. This class implements all of the behavior that is "peculiar to 'us'," and does so "once, for all." Every other developer around here can now "instantiate it and forget it."