PDA

View Full Version : Customized sorting of rows on columnHeader click in GridPanel



abjax
5 Sep 2010, 6:34 AM
By default on click of column header, the rows of a GridPanel get sorted in ascending or descending order.
How do we make it sort in accordance to our logic? Please assist me with full code snippets
TIA

laurentParis
5 Sep 2010, 9:43 PM
extend Ext.store by your own store and override createSortFunction

on src file, createSortFunction seems like


/**
* @private
* Creates and returns a function which sorts an array by the given field and direction
* @param {String} field The field to create the sorter for
* @param {String} direction The direction to sort by (defaults to "ASC")
* @return {Function} A function which sorts by the field/direction combination provided
*/
createSortFunction: function(field, direction) {
direction = direction || "ASC";
var directionModifier = direction.toUpperCase() == "DESC" ? -1 : 1;

var sortType = this.fields.get(field).sortType;

//create a comparison function. Takes 2 records, returns 1 if record 1 is greater,
//-1 if record 2 is greater or 0 if they are equal
return function(r1, r2) {
var v1 = sortType(r1.data[field]),
v2 = sortType(r2.data[field]);

return directionModifier * (v1 > v2 ? 1 : (v1 < v2 ? -1 : 0));
};
},


change comparison function by you own logic )