DSCF4260

Grouping on multiple columns in extjs 4

Yes, you can still add multiple columns to a grouping grid, and it’s not that hard, you just have to look in the store!

To add a second or even third column to an extjs grid all you now have to is add the extra columns in the store’s getGroupString property. The code below illustrates the addition of a second value when the group string equals some_property.

var some_data_store = Ext.create('Ext.data.Store', {
     storeId:'some_data_store',
     groupField:'some_property',
    getGroupString: function(instance) {
	   var group = this.groupers.first();
  	   if (group) {
       	      if (group.property == 'some_property') {
		 return instance.get(group.property) + ' (' + instance.get('my_second_property') + ') ';
	    }
	  return instance.get(group.property);
		   }
		   return '';
		},
	model:'some_data_model',
	autoLoad:true,
	proxy: {
        	type: 'ajax',
        	url : 'some_url.php',
        	reader: {
            	type: 'json',
            	root: 'data'
        }
}
});

5 thoughts on “Grouping on multiple columns in extjs 4”

Leave a Reply