PDA

View Full Version : Bug with TreeSorter's "property" config option


weston.ruter
07-22-2007, 01:22 PM
I came across a bug in the class Ext.tree.TreeSorter (in TreeSorter.js). When trying to set the TreeSorter "property" config option from "text" to another attribute by which to sort, an exception is raised: "n1[p] has no properties" and "n2[p] has no properties" on the following lines:

var v1 = sortType ? sortType(n1) : (cs ? n1[p] : n1[p].toUpperCase());
var v2 = sortType ? sortType(n2) : (cs ? n2[p] : n2[p].toUpperCase());

I examined the TreeNode properties and saw that the "text" property is defined twice: first as a property of TreeNode itself, and second as a property of the TreeNode's "attributes" collection. Apparently, the default value "text" for the TreeSorter "property" config option is supposed to be referencing the "text" property in the "attributes" collection but it is mistakenly referencing the "text" property directly on TreeNode. To fix this, the lines need to be changed to something like the following:

var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());

However, when the "property" config option refers to a value which is not a string type, another error is raised that "toUpperCase" is not a valid function. Therefore the previous revision needs to be further revised as follows:

var v1 = sortType ? sortType(n1) : (cs || !n1.attributes[p].toUpperCase ? n1.attributes[p] : n1.attributes[p].toUpperCase());
var v2 = sortType ? sortType(n2) : (cs || !n2.attributes[p].toUpperCase ? n2.attributes[p] : n2.attributes[p].toUpperCase());

mystix
07-22-2007, 02:00 PM
http://extjs.com/forum/showthread.php?t=8887

jack.slocum
07-23-2007, 05:09 AM
The first issue has been changed in SVN.

For the second, if you are sorting on non-string values you will have to set caseSensitive: true (it defaults to false).