7

I am using ExtJs 4.1 framework. I have a grid which shows only one column (Name). The grid is associated with a store which have two fields (Name and SortOrder). The field "name" in store is associated with Name column of the grid. I want to sort the name column based on the value available in SortOrder field in the store. How can I implement such logic.

Thank you

SharpCoder
  • 18,279
  • 43
  • 153
  • 249

3 Answers3

20

There is also a little simpler solution:

...
columns: [{
    header: 'Name',
    dataIndex: 'Name',
    sortable: true,
    getSortParam: function() {
        return 'SortOrder';
    }
...
}]
...

So instead of overriding doSort() you can just override getSortParam() method (which is used by doSort()).

Arshak
  • 716
  • 2
  • 7
  • 15
  • This solved this issue for me too, but your other referenced field (`SortOrder` in this case) has its own column, you might need give it a different data index and override its `getSortParam` function too. No really sure why though... – Sash May 20 '15 at 15:47
  • 3
    Definitely much better, because it's a public method. Thanks! – Leonardo Spina Oct 04 '16 at 15:43
4

Do you mean something like this:

...
columns: [{
    header: 'Name',
    dataIndex: 'Name',
    sortable: true,
    doSort: function(state){
        var ds = this.up('tablepanel').store;
        ds.sort({
            property: 'SortOrder',
            direction: state
        });
    }
    ....    
}]
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • Thanks.... wonder why they didn't put that "doSort" into Ext.grid.column.Column's documentation. +1 for you – T1000 May 10 '12 at 07:43
  • 1
    Be aware, Ext.grid.column.Column.doSort() is a private method used for internal processing and as such is not generally recommended for use by us. Because of this, in documentation it is not visible, unless you search for it specifically or enable the viewing of private functions. – Yetti Dec 16 '13 at 22:57
0

Another way to do that on Header click.

columns: [
    {
        header: 'Name',
        dataIndex: 'Name',
        listeners: {
            headerclick: function() {
                var store = this.up('grid').getStore();
                store.sort({
                        property: 'SortOrder',
                        direction: this.sortState
                    });
            }
        }
    }
 ]
scs
  • 119
  • 7