1. #1
    Ext User
    Join Date
    Mar 2007
    Location
    Japan
    Posts
    14
    Vote Rating
    0
    cornyflake is on a distinguished road

      0  

    Lightbulb [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:
    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});
    Why?

    TreeSorter.js Lines 75-76:
    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());
    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.

    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

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    I would suggest:
    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());
    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.

  3. #3
    Ext User
    Join Date
    Mar 2007
    Location
    Japan
    Posts
    14
    Vote Rating
    0
    cornyflake is on a distinguished road

      0  

    Default


    Quote Originally Posted by Condor View Post
    I would suggest:
    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());
    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.
    Condor,

    Dates, etc. converted to strings do not sort properly. Thank you for your prompt reply!

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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;

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,055
    Vote Rating
    659
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    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!

  6. #6
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,055
    Vote Rating
    659
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    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:

    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.
    It could be a possible enhancement to allow a Ext.data.SortType, but I'll close this one off for now.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  7. #7
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    True, I also don't think it's a bug, but I would still recommend changing:
    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());
    because otherwise caseSensitive:false could throw a javascript error when the attribute isn't a string.

    ps. And the API docs could also use a note that caseSensitive:true causes the attribute to be converted to string before sorting.

  8. #8
    Sencha User
    Join Date
    Nov 2010
    Posts
    7
    Vote Rating
    0
    ejatin is on a distinguished road

      0  

    Exclamation 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 ???

  9. #9
    Sencha User
    Join Date
    Nov 2010
    Posts
    7
    Vote Rating
    0
    ejatin is on a distinguished road

      0  

    Default 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.

Thread Participants: 3