1. #1
    Sencha Premium Member
    Join Date
    May 2008
    Posts
    24
    Vote Rating
    0
    renoye is on a distinguished road

      0  

    Default Answered: grid custom sort

    Answered: grid custom sort


    Hi, all:

    I have a very simple question about sort a grid column.
    Let's say I have a field called 'name' and its type is string.
    after sort, all the data list as
    'abc1'
    'abc10'
    'abc2'
    'abd27'
    'abd3'
    I want them list as
    'abc1'
    'abc2'
    'abc10'
    'abd3'
    'abd27'

    so basically I have to split the string, compare the alpha word first, then compare the number. That is why I do not see sortType gona help me here. It takes a value and output a comparable value. I do not know how to generate a comparable value for this situation.

    I know I can define sorterFn at store.sorters. but that will only work initially and every time I click column head to sort, it still will generate wrong result. Any help here?

  2. 1. The first solution is use sortType(value) to transform input value to a suitable format for sorting. For example:
    abc1 -> abcAAAAAAA0000000001
    abc10 -> abcAAAAAAA0000000010
    abc2 -> abcAAAAAAA0000000002
    abd27 -> abdAAAAAAA0000000027

    2. The second solution is overriding the doSort() method to define your own sorting function
    Code:
    var grid = Ext.create('Ext.grid.panel',{
        ...
        columns: [{
            text: 'Name',
            sortable : true,
            dataIndex: 'name',
            doSort: function(state) {
                var ds = this.up('tablepanel').store;
                var field = this.getSortParam();
                ds.sort({
                    property: field,
                    direction: state,
                    sorterFn: function(v1, v2){
                        v1 = v1.get(field);
                        v2 = v2.get(field);
                        // transform v1 and v2 here
                        return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
                    }
                });
            }
       ....  
    });

  3. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      1  

    Default


    1. The first solution is use sortType(value) to transform input value to a suitable format for sorting. For example:
    abc1 -> abcAAAAAAA0000000001
    abc10 -> abcAAAAAAA0000000010
    abc2 -> abcAAAAAAA0000000002
    abd27 -> abdAAAAAAA0000000027

    2. The second solution is overriding the doSort() method to define your own sorting function
    Code:
    var grid = Ext.create('Ext.grid.panel',{
        ...
        columns: [{
            text: 'Name',
            sortable : true,
            dataIndex: 'name',
            doSort: function(state) {
                var ds = this.up('tablepanel').store;
                var field = this.getSortParam();
                ds.sort({
                    property: field,
                    direction: state,
                    sorterFn: function(v1, v2){
                        v1 = v1.get(field);
                        v2 = v2.get(field);
                        // transform v1 and v2 here
                        return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
                    }
                });
            }
       ....  
    });

  4. #3
    Sencha Premium Member
    Join Date
    May 2008
    Posts
    24
    Vote Rating
    0
    renoye is on a distinguished road

      0  

    Default


    thank you.
    it is very helpful

  5. #4
    Sencha User
    Join Date
    Apr 2013
    Location
    USA
    Posts
    7
    Vote Rating
    0
    neelua9 is on a distinguished road

      0  

    Default


    How can we override globally, something like Ext.override(Ext.grid.column.Column, { doSort:function(){}});
    Neilu

Thread Participants: 2

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