Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting one column based on another column in ExtJs 4.1 grid

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

like image 775
SharpCoder Avatar asked May 04 '12 08:05

SharpCoder


2 Answers

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()).

like image 129
Arshak Avatar answered Sep 26 '22 07:09

Arshak


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
        });
    }
    ....    
}]
like image 33
Sudhir Bastakoti Avatar answered Sep 23 '22 07:09

Sudhir Bastakoti