2

I have a groupped grid. All the items are collapsed at the start. I want to achieve the functionallity that only one group can be expanded at once. My idea was the following: On group click collapse all the groups and expand the clicked group again. But I am stuck at the first part (collapsing all the groups). I get the following error in browser console:

Error:

Uncaught TypeError: Cannot call method 'onRefresh' of undefined .... Grouping.js

Code:

 onGroupingGroupclick()view, node, group, eOpts){
       view.collapseAll(); //error
    }

If my approach is not ok for some reason I would kindly ask for any alternatives...

Jacob
  • 3,580
  • 22
  • 82
  • 146

1 Answers1

3

view variable in your groupclick event listener contain instance of Ext.view.Table. But you have to call collapseAll() method on instance of Ext.grid.feature.Grouping feature which you use in your grid for grouping.

So your grid config should be like this:

features: [{
    ftype:'grouping',
    startCollapsed: true       
}],    
listeners: {
    groupclick: function (view, node, group, e, eOpts) {

        view.features[0].collapseAll();
        view.features[0].expand(group);
    }
}

See live example in this fiddle: https://fiddle.sencha.com/#fiddle/2f8

Akatum
  • 3,976
  • 2
  • 18
  • 25
  • I had to bind your code to "groupexpand" event because the "gropuclick" would not fire. Now I get view.features is undefined – Jacob Jan 06 '14 at 09:48
  • I know and thanks for the help. But not my groupclick event doesn't fire and I am stuck there. – Jacob Jan 06 '14 at 09:58
  • Which subversion of ExtJs 4.2 are you using? Do you have listener for `gropuclick` event defined on `grid` component? – Akatum Jan 06 '14 at 10:04
  • I have it defined under my grouping feature. I am using Ext JS 4.2.x – Jacob Jan 06 '14 at 10:07
  • You have to defined listener on `grid` (as i have it in the fiddle). The `groupclick` event is fired by grid, not by grouping feature. – Akatum Jan 06 '14 at 10:13
  • But if I look under grid I cannot add it. I am doing this in architect – Jacob Jan 06 '14 at 10:20
  • I have added the function manually. Wasn't aware that you could do that! Now it is working. Thank you! – Jacob Jan 06 '14 at 10:24