I would like to share with you this little upgrade of Ext.grid.ColumnModel.
I've added a new options for each column: sortIndex.
This options aims to split between dataIndex (used to find property inside the related store) and storeIndex (property name used to sort data).
In my example I've two fields encapsulate the same semantic:
- date (a simple javascript date object)
- dateToString (locale-rappresentation of the date - created runtime as a new field without using renderer)
In grid I would like to show dateToString field and aims user to remotely sort this field using date property (dateToString isn't a server-side property). With this upgrade you can do this!
Here my little code:
Code:
Ext.grid.ColumnModel.override({
getSortIndex : function(col) {
return this.config[col].sortIndex || this.config[col].dataIndex;
},
findColumnIndex : function(dataIndex){
var c = this.config;
for(var i = 0, len = c.length; i < len; i++){
if(c[i].dataIndex == dataIndex || c[i].sortIndex == dataIndex){
return i;
}
}
return -1;
}
});
Ext.grid.GridView.override({
onHeaderClick : function(g, index){
if(this.headersDisabled || !this.cm.isSortable(index)){
return;
}
g.stopEditing(true);
g.store.sort(this.cm.getSortIndex(index));
}
});
here usage:
Code:
...., {
header: "Date",
sortable: true,
dataIndex: "date",
sortIndex: "dateToString",
width: 35
}, ....
have fun 