-
12 Dec 2008 7:12 AM #1
[CLOSED][2.2] TreeSorter's "caseSensitive" must be set for "property" to work
[CLOSED][2.2] TreeSorter's "caseSensitive" must be set for "property" to work
If you set the TreeSorter config's "property" to a non-string node attribute, it will throw an error. To fix this you must set "caseSensitive" to true.
Example:
Why?Code:var tree = new Ext.tree.TreePanel({ root: new Ext.tree.TreeNode({text: 'Kill Babies', children: [ {valueToSortOn: 1}, {valueToSortOn: 2} ]}) }); // Example 1: Doesn't work new Ext.tree.TreeSorter(tree, {property: 'valueToSortOn'}); // Example 2: Works! new Ext.tree.TreeSorter(tree, {property: 'valueToSortOn', caseSensitive: true});
TreeSorter.js Lines 75-76:
As you can see, without caseSensitive set to true, it calls toUpperCase() on whatever the value is. If it's an integer, etc. which doesn't have that method, it'll crap out.Code:// Note: cs = caseSensitive 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());
This has been discussed in the 1.x forums (https://extjs.com/forum/showthread.php?t=9733), but continues into 2.0.
Having to set an unrelated config property to get another to work is unset. Please either fix the code or at least put it in the API documentation.
Thanks!
Blake
-
12 Dec 2008 7:42 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
I would suggest:
Note: The code for the sortFn function should be moved from the constructor to the doSort method. That way you can change the sorting options without having to create a new TreeSorter.Code:var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : String(n1.attributes[p]).toUpperCase()); var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : String(n2.attributes[p]).toUpperCase());
-
12 Dec 2008 6:04 PM #3
-
12 Dec 2008 10:35 PM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
That is to be expected. The API docs should also mention that you should set caseSensitive:true if you want to sort on the actualy type.
Or maybe the caseSensitive default should be changed to:
Code:var cs = this.caseSensitive !== false;
-
12 Dec 2008 10:38 PM #5
I think it would be nice to pass in a SortType, same as for a field. Also, a custom sortFn would be good, as the previous poster suggested.
I'll put this as a possible improvement.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
15 Dec 2008 11:28 PM #6
After reviewing this again, I don't think this is a bug. The TreeSorter provides the opportunity for you to cast the value appropriately, as it says in the docs:
It could be a possible enhancement to allow a Ext.data.SortType, but I'll close this one off for now.A custom "casting" function used to convert node values before sorting. The function will be called with a single parameter (the Ext.tree.TreeNode being evaluated) and is expected to return the node's sort value cast to the specific data type required for sorting. This could be used, for example, when a node's text (or other attribute) should be sorted as a date or numeric value. See the class description for example usage. Note that if a sortType is specified, any property config will be ignored.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
15 Dec 2008 11:36 PM #7Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
True, I also don't think it's a bug, but I would still recommend changing:
because otherwise caseSensitive:false could throw a javascript error when the attribute isn't a string.Code:var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : String(n1.attributes[p]).toUpperCase()); var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : String(n2.attributes[p]).toUpperCase());
ps. And the API docs could also use a note that caseSensitive:true causes the attribute to be converted to string before sorting.
-
7 Apr 2011 3:03 AM #8
still its bug for me ...
still its bug for me ...
for my app, i am using sortType for my tree.
function in sortType returns me folder's name (records's display_name property), on which i want to sort.
but
var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : ...
will ignore config caseSensitive.
Why shouldnt i use property config is : text property of folder consist number (unread counter of mails)
and if string contains a number, it will be placed at top, and parent tree wont be sorted. (like drafts will be place above Inbox. but inbox(10) will be place above drafts) so property config cannot be used.
hence, when you are using sortType, caseSensitive config is for no use.
this looks like a bug, isnt it ???
-
7 Apr 2011 4:01 AM #9
PS :
PS :
addition to above post
to display unread counter beside folder name, we have to use <span>
so in comparing string with text (if you use property config) symobs '>', '<' will destroy sorting manner.


Reply With Quote