PDA

View Full Version : [Ext 3.0] - Multi column sort



imnilesh
30 Aug 2009, 9:43 PM
Hi,

I used the function sortData() function for multi-column sort at the Ext 2 thread:
http://www.extjs.com/forum/showthread.php?p=380790

The function works fine for me in Ext 3, but it do not refreshes the grid with the new sort. I verified 'datachanged' event is generated still new sorted data is not refreshed in the grid.

My code:



Ext.override(Ext.data.Store, {

sortData : function(f, direction){
// test sortInfo
var multipleSortInfo = [{field: 'number', direction: 'ASC'}, {field: 'name', direction: 'DESC'}];
direction = direction || 'ASC';

var st = this.fields.get(field).sortType;

var fn = function(r1, r2) {
var ret = 0;
for (i = 0; (multipleSortInfo !== undefined && ret == 0 && i < multipleSortInfo.length); i++) {
var v1 = st(r1.data[field]), v2 = st(r2.data[field]);
var x1 = r1.data[multipleSortInfo[i].field], x2 = r2.data[multipleSortInfo[i].field];
var dir = (direction != multipleSortInfo[i].direction) ? direction
.toggle("ASC", "DESC") : direction;
ret = (x1 > x2) ? 1 : ((x1 < x2) ? -1 : 0);
if (dir == 'DESC')
ret = -ret;
};
return ret;
};

this.data.sort(direction, fn);
if (this.snapshot && this.snapshot != this.data) {
this.snapshot.sort(direction, fn);
}
}


Am I missing anything here ?

Thanks.