1. #1
    Sencha Premium Member
    Join Date
    Jun 2011
    Location
    Kaiserslautern, Germany
    Posts
    7
    Vote Rating
    0
    Answers
    2
    Kotolom is on a distinguished road

      0  

    Default Answered: Custom sort in tree column. Sorter in store impelmented, but the column uses its own

    Answered: Custom sort in tree column. Sorter in store impelmented, but the column uses its own


    hi all
    this is the code in tree store
    Code:
    Ext.define('data.store.AssetTreeStore', {
        extend: 'Ext.data.TreeStore',
            sorters: [
                          {
                              // natural sort                           
                             sorterFn:  function (rec1, rec2) {
                              <some code>
                         }
                        ]
    ...
    });
    When the tree is first time loaded (on page load) the items are sortet using the sorter I implemented in store. But when I click on the header the tree uses its own sorter.

    What I'm doing wrong?

  2. I've got it.

    I have to add the 'sort' function to the store.

    Code:
        sort: function(sorters, direction) {
            var me = this;
    
            if(sorters && sorters.property == 'title') {
                if(sorters.direction == 'ASC') {
                    return this.doSort(function(rec1, rec2) {
                        return Util.String.compareNatural(rec1.get('title'), rec2.get('title'));
                    });
                } else {
                    return this.doSort(function(rec1, rec2) {
                        return -Util.String.compareNatural(rec1.get('title'), rec2.get('title'));
                    });
                }
            }
    
            return me.callParent(arguments);
        }

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,599
    Vote Rating
    434
    Answers
    3102
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    When you click on the tree grid column header, it will only use the one sorter based on the header. It won't add a sort to the existing array of sorters.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha Premium Member
    Join Date
    Jun 2011
    Location
    Kaiserslautern, Germany
    Posts
    7
    Vote Rating
    0
    Answers
    2
    Kotolom is on a distinguished road

      0  

    Default


    Well, that's clear to me.
    But when you look at this example http://jsfiddle.net/cvdNW/3/
    you will find the sort implemented in store and used on header click.

    So the right question is: how can I use a custom sort on header click in a tree column?
    And I can't apply it to a field in the model, because this would affect other components thas are using the model.

    All solutions I found use the store to impelment a custom sort.

  5. #4
    Sencha Premium Member
    Join Date
    Jun 2011
    Location
    Kaiserslautern, Germany
    Posts
    7
    Vote Rating
    0
    Answers
    2
    Kotolom is on a distinguished road

      0  

    Default


    I've got it.

    I have to add the 'sort' function to the store.

    Code:
        sort: function(sorters, direction) {
            var me = this;
    
            if(sorters && sorters.property == 'title') {
                if(sorters.direction == 'ASC') {
                    return this.doSort(function(rec1, rec2) {
                        return Util.String.compareNatural(rec1.get('title'), rec2.get('title'));
                    });
                } else {
                    return this.doSort(function(rec1, rec2) {
                        return -Util.String.compareNatural(rec1.get('title'), rec2.get('title'));
                    });
                }
            }
    
            return me.callParent(arguments);
        }

Tags for this Thread