1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Answers
    1
    Vote Rating
    0
    claritee is on a distinguished road

      0  

    Default Answered: Sorting a store when record field with no value

    Answered: Sorting a store when record field with no value


    Hello,

    I have been adding sorters on a store and noticed that if a record does not have a value for a field remains at the top of the sort.

    Just wondering is there a way to order these records to the end of the list?

    Code:
    --- The Store ---
    Ext.define('MyApp.store.PropertySummaries', {
        extend: 'Ext.data.Store',
        xtype: 'PropertySummaries',
    
    
        config: {
            model: 'MyApp.model.PropertySummary',
            sorters: ['propertyName', 'minPrice', 'maxAdults', 'consumerRating']
        }
    });
    ....
    
    --- called by ---
    theStore.sort('consumerRating', 'DESC');
    In this case if there is no consumerRating, I want the record to be at the bottom of the list.

    Thanks in advance!

  2. You could add your own Ext.util.Sorter with a custom sortFn to the store's sorters.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,782
    Answers
    3465
    Vote Rating
    833
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You could add your own Ext.util.Sorter with a custom sortFn to the store's sorters.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    12
    Answers
    1
    Vote Rating
    0
    claritee is on a distinguished road

      0  

    Default


    Thanks for the quick reply!

    I tried with the below and that worked

    Code:
    theStore.sort([{
        direction: 'ASC',
        sorterFn: function(o1, o2) {
            return compare(o1.data.consumerRating, o2.data.consumerRating);
        }
    }]);
    
    ....
    
    
    
    theStore.sort([{
        direction: 'DESC',
        sorterFn: function(o1, o2) {
            return compare(o1.data.consumerRating, o2.data.consumerRating);
        }
    }]);
    
    
    .... // etc ....
    
    ....
    // not the most elegant
    function compare(value1, value2) {
        if (!value1 || value1 == '') {
            return -1;
        }
        if (!value2 || value2 == '') {
            return 1;
        }
        if (value1 > value2) {
            return 1;
        }
        if (value1 == value2) {
            return 0;
        }
        return -1;
    }
    I was wondering if there is a way to define multiple sorterFns?
    I tried to define multiple sorter functions but I think there is an error somewhere as the sorterFn isn't getting invoked (or default one is being invoked)

    Code:
    Ext.define('StayzApp.store.PropertySummaries', {
        extend: 'Ext.data.Store',
        xtype: 'PropertySummaries',
    
    
        config: {
            model: 'StayzApp.model.PropertySummary',
            sorters: [
                {property : 'propertyName'},
                {property : 'minPrice'}, // TODO also define custom sorterFn
                {property : 'maxAdults'}, // TODO also define custom sorterFn
                {
                    property : 'consumerRating',
                    sorterFn: function(o1, o2) {
                        return compare(o1.data.consumerRating, o2.data.consumerRating);
                    }
                }
            ]
        }
    });
    
    --- and to invoke ---
    
    theStore.sort('consumerRating', 'ASC'); or
    theStore.sort('consumerRating', 'DESC');
    Thanks for your help

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi