PDA

View Full Version : PagingMemoryProxy sorting problem



madamut
29 Oct 2009, 1:39 PM
I'm using PagingMemoryProxy to display a grid. The store is configured with the 'remoteSort:true'. So the sorting is supposed to be handled by the proxy which takes the server place and should provide both pagination and sorting. It looks like in 3.0 version the sorting is broken. On a closer look there is a code change from 3.0 version of the PagingMemoryProxy and the 2.x one.

3.0


var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
var fn = function(r1, r2){
return r1 < r2;
};
result.records.sort(function(a, b){
var v = 0;
if (typeof(a) == 'object') {
v = fn(a.data[params.sort], b.data[params.sort]) * dir;
}
else {
v = fn(a, b) * dir;
}
if (v == 0) {
v = (a.index < b.index ? -1 : 1);
}
return v;
});
2.x code:


var dir = String(params.dir).toUpperCase() == "DESC" ? -1 : 1;
var fn = function(v1, v2){
return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
};
result.records.sort(function(a, b) {
var v = 0;
if (typeof(a)=="object"){
v = fn(a.data[params.sort], b.data[params.sort]) * dir;
} else {
v = fn(a, b) * dir;
}
if (v==0) {
v = (a.index < b.index ? -1 : 1);
}
return v;
});
Looks like the "fn" function in the 3.0 now returns a boolean where it should return a integer like the 2.0 one, which causes the sort algorithm to fail. Is this supposed to be like this, or it is a bug?

madamut
2 Nov 2009, 10:51 AM
Can somebody check if this is a bug or not?
Thanks!

Animal
2 Nov 2009, 11:07 AM
Looks like a bug. When you change the code back your sorts all work OK?

madamut
2 Nov 2009, 11:11 AM
Yes, it works fine.

Animal
2 Nov 2009, 12:01 PM
Report it in the bugs forum. Looks like a simple fix.

madamut
2 Nov 2009, 12:03 PM
ok, will do, thanks.