PDA

View Full Version : [3.2.x Remote multi-sorting for Store]



Slider
12 Apr 2010, 8:54 AM
Juste write a little Ext Store hook to allow remote Multisorting, hope it'll help.
All sorters will be post to the load request within a table: sort[0], sort[1], sort[2], .... and dir[0], dir[1], dir[2], ...



Ext.override(Ext.data.Store, {
load : function(options) {
options = options || {};
this.storeOptions(options);
if(!this.multiSortInfo && this.sortInfo && this.remoteSort){
var pn = this.paramNames;
options.params = options.params || {};
options.params[pn.sort] = this.sortInfo.field;
options.params[pn.dir] = this.sortInfo.direction;
}
if(this.multiSortInfo && this.remoteSort){
var pn = this.paramNames;
options.params = options.params || {};
sorters = this.multiSortInfo.sorters;

for (var i = 0, len = sorters.length; i < len; i++)
{
sorter = sorters[i];
fieldParamName = pn.sort+'['+i+']';
dirParamName = pn.dir+'['+i+']';
options.params[fieldParamName] = sorter.field;
options.params[dirParamName] = sorter.direction;
}
}
try {
return this.execute('read', null, options); // <-- null represents rs. No rs for load actions.
} catch(e) {
this.handleException(e);
return false;
}
},
multiSort: function(sorters, direction) {
this.hasMultiSort = true;
direction = direction || "ASC";

//toggle sort direction
if (this.multiSortInfo && direction == this.multiSortInfo.direction) {
direction = direction.toggle("ASC", "DESC");
}

/**
* @property multiSortInfo
* @type Object
* Object containing overall sort direction and an ordered array of sorter configs used when sorting on multiple fields
*/
this.multiSortInfo = {
sorters : sorters,
direction: direction
};

if (this.remoteSort) {
this.load(this.lastOptions);
} else {
this.applySort();
this.fireEvent('datachanged', this);
}
}
});