View Full Version : GroupingView extention - toggle just the nominated group

20 Apr 2009, 7:57 PM

I have a couple of grouping views in my app. On one of them I wanted the default display to expand just the first group and collapse the others. On another grouping view I wanted the last group expanded and all the others collapsed.

Here is my solution:

Ext.grid.GroupingView.prototype.toggleGroupIndex = function(groupIndex,expanded){
// Toggle just the group that is specified by the groupIndex
// (ie the array index) in the direction of the expanded parameter,
// and toggle all the other groups in the opposite direction

// Get all the groups
var groups = this.getGroups();
if (groups.length) {
// groupIndex -1 means the last group
if (groupIndex==-1){groupIndex = groups.length-1}

if (groups.length >= groupIndex) {
if (expanded) {
else {
this.toggleGroup(groups[groupIndex], expanded);

and you use it like:

myGroupingView.toggleGroupIndex(0,true); // Expand first group, collapse the others
myOtherGroupingView.toggleGroupIndex(-1,true); // Expand last group, collapse the others

You can also do eg myGroupingView.toggleGroupIndex(0,false); to collapse the first group and expand the others.


22 Apr 2009, 2:11 AM
posted in the wrong forum - I've moved it to the correct forum

22 Apr 2009, 1:50 PM
Thanks, sorry about that!