View Full Version : How to exclude certain rows from sorting?

7 Nov 2011, 7:11 AM
Hi all.

I am new to ExtJS and i have written an web-application which features a GridPanel (grouped and ungrouped) and I want to prevent sorting certain rows (which represent summary rows).

I have already tried
but it didn't work for me.

I am using ExtJS 3.4.

Can somebody give some hints. Thank you very much in advance.

7 Nov 2011, 11:38 AM
If you don't want a column to be sortable by clicking on the header, specify the 'sortable' config to false on the column.

7 Nov 2011, 1:43 PM
Hi mitchellsimoens,

thanks for your reply.

I dont't want to prevent sorting on a column. I want to exclude certain rows from sorting.
I tried to remove the rows when the sortchange event is fired and insert them afterwards at the same position in the grid. But this only works for ungrouped grids.

An alternative approach would be to create a custom sorting function. All the examples I found didn't fit my needs.

I tried the following code (http://www.sencha.com/forum/showthread.php?12433-Adding-a-row-in-a-grid-s-footer), but I always get the error "this.fields.get(f) is undefined".

Ext.data.MyGroupingStore = Ext.extend(Ext.data.GroupingStore, {
// private
sortData : function(f, direction){
direction = direction || 'ASC';
var st = this.fields.get(f).sortType;
var fn = function(r1, r2){
var row_type1 = r1.data['row_type'];
var row_type2 = r2.data['row_type'];
if ((row_type1 == 'sum') && (direction == 'ASC'))
return 1;
if ((row_type2 == 'sum') && (direction == 'ASC'))
return -1;
if ((row_type1 == 'sum') && (direction == 'DESC'))
return -1;
if ((row_type2 == 'sum') && (direction == 'DESC'))
return 1;

var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);

this.data.sort(direction, fn);
if(this.snapshot && this.snapshot != this.data){
this.snapshot.sort(direction, fn);

Is there a detailed example of how to create a custom sorting function?

Thanks in advance!

8 Nov 2011, 7:57 AM
What would be the use case for that?

8 Nov 2011, 12:44 PM
Hi scarsick,

the rows that i want to leave on the same position are representing summary rows in the GridPanel.
After examing the source code I was able to solve the problem.