Sort one column based on another column in ExtJs 4.1 grid

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

thanks

+7
source share
3 answers

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 }); } .... }] 
+4
source

There is also a slightly simpler solution:

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

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

+19
source

Another way to do this is by clicking on the title.

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

All Articles