PDA

View Full Version : Define a sort method on grid for a specific column



shiyaojun
17 Mar 2014, 10:32 PM
The column values is consisted by 3 values thourg the record below:
{
text: 'ColumnA'
renderer: this.display3values,
dataIndex: 'dimensions',
flex: 3
}


display3values: function(value, metaData, record, rowIndex, colIndex, store, view) {
var str = record.get('aaa') + ' × ' + record.get('bbb') + ' × ' + record.get('ccc');
return str ;
},
But it will have problem when user want to sort it
If I want to sort the column by the product of the 3 values, how should I do ?

Farish
18 Mar 2014, 12:14 AM
the doSort method of the grid column can be used to implement a custom sorting function. take a look at this:

http://stackoverflow.com/questions/17795019/ext-js-sorting-custom-column-by-contents

shiyaojun
18 Mar 2014, 12:47 AM
Thanks for replay
But this is a bit different with my issue
Could you give more details ? Thanks a lot

shiyaojun
18 Mar 2014, 11:35 PM
the doSort method of the grid column can be used to implement a custom sorting function. take a look at this:

http://stackoverflow.com/questions/17795019/ext-js-sorting-custom-column-by-contents

doSort: function(state) {
var ds = this.up('grid').getStore();
var field = this.getSortParam();


ds.sort({
property: field,
direction: state,
sorterFn: function(v1, v2) {
v1 = v1.get('length') * v1.get('height') * v1.get('width');
v2 = v2.get('length') * v2.get('height') * v2.get('width');
return v1 > v2 ? (v1 < v2 ? -1 : 0) : 1;
}
});
}

I have updated my code like this, but which only can sort the custom column on one direction,how can I control the sort direction ? I debugger it, the state is empty