PDA

View Full Version : Sorting one column based on another column



webfriend13
4 May 2012, 12:12 AM
Hi All,

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

vietits
4 May 2012, 12:47 AM
If you use remote sort then this is your server side script task. If you use local sort, then below is my suggestion:


...
columns: [{
header: 'Name',
dataIndex: 'Name',
sortable: true,
doSort: function(state){
var ds = this.up('tablepanel').store;
ds.sort({
property: 'SortOrder',
direction: state
});
}
....
}]

webfriend13
4 May 2012, 1:00 AM
Hi Vietits,

Thank you for quick reply. What is the use of "this.up('tablepanel').store;" ? Are you trying to get the store associated with the grid? what is tablepanel in this case?

vietits
4 May 2012, 1:06 AM
Hi Vietits,

Thank you for quick reply. What is the use of "this.up('tablepanel').store;" ? Are you trying to get the store associated with the grid? what is tablepanel in this case?
Yes, this.up('tablepanel').store is get the store associated with the grid. Here tablepanel is alias of Ext.panel.Table which is parent class of Ext.grid.Panel. So this.up('tablepanel') is get reference to the grid panel (in case you use Ext.grid.Panel) or tree panel (in case you use Ext.tree.Panel)

webfriend13
4 May 2012, 1:18 AM
Hi Vietits,

Thank you. Sorting is now working as I wanted it to work. Appreciate your help.