PDA

View Full Version : [OPEN-1327] TreeSorter cannot sort numerical attributes



Traktopel
13 Oct 2010, 8:09 AM
Ext version tested:


Ext 3.3



Adapter used:


ext




Description:


When you want to sort your nodes using an numerical attributes in your node(immagine a sortIndex computed), you may want to follow the doc so you put the property token to 'sortIndex' and you do not provide sortType fn.

In the treeSorter code,
(Ext.isString(sortType)) is false so sortType fn is still undefined so if caseSensitive is not defined, it tries to uppercase a integer .... boom

The documentation should also mention that it is possible to use the Ext.data.SortTypes as text in sortTypes



if(Ext.isString(sortType)){
sortType = Ext.data.SortTypes[sortType];
}
this.sortFn = function(n1, n2){
var attr1 = n1.attributes,
attr2 = n2.attributes;


if(folderSort){
if(attr1[leafAttr] && !attr2[leafAttr]){
return 1;
}
if(!attr1[leafAttr] && attr2[leafAttr]){
return -1;
}
}
var prop1 = attr1[prop],
prop2 = attr2[prop],
v1 = sortType ? sortType(prop1) : (caseSensitive ? prop1 : prop1.toUpperCase());
v2 = sortType ? sortType(prop2) : (caseSensitive ? prop2 : prop2.toUpperCase());

Condor
13 Oct 2010, 8:19 AM
I don't see a problem, apart from the fact that you have to specify caseSensitive:true to be able to sort numerical values (which could be added to the docs).

Traktopel
13 Oct 2010, 8:26 AM
you have to specify caseSensitive:true to be able to sort numerical values.


I don't see a problem

So neither do I ;-)