PDA

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



murrah
20 Apr 2009, 7:57 PM
Hi,

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) {
this.collapseAllGroups();
}
else {
this.expandAllGroups();
}
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.

Murray

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

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