Author Topic: Get the collapsed state of a group?  (Read 2186 times)

MEngelbyPQ

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
Get the collapsed state of a group?
« on: May 04, 2018, 03:00:02 am »
Is there a way to retrieve the collapsed state of a group from within a toolbar item listener function?  I have only 1 group and this is what I came up with, but it is pretty janky.  All the commented out lines are things that I've tried.
Code: [Select]
                        {
                            type:'button',
                            label: 'Toggle Sites',
                            listener: function() {
                                //var $siteGrpOpts = this.groupOption('collapsed');
                                var $site = this.Group();
                                 window.siteCollapsed = !window.siteCollapsed;
                                 if (window.siteCollapsed) {
                                    $site.collapse();
                                 } else {
                                    $site.expand();
                                 }
                                //var $siteState = this.option('groupModel.collapsed[0]');
                                //var $siteState1 = $site.option.collapsed;
                                //var $siteState2 = $site.groupOption('collapsed');
                                //this.groupOption('collapsed', !$siteState1);
                            }
                        },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Get the collapsed state of a group?
« Reply #1 on: May 04, 2018, 09:16:29 am »
Please try this

Code: [Select]
listener: function () {
     this.Group().option({
           collapsed: [!this.option('groupModel.collapsed')[0]]
     });
}

MEngelbyPQ

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Get the collapsed state of a group?
« Reply #2 on: May 05, 2018, 12:58:20 am »
Many thanks!  The answer seems obvious once it has been pointed out and I know where in the documentation to look.  But for whatever reason, my mind wasn't figuring out how to read options for the groupModel.

Is there a way to contribute to the documentation?  This may be helpful to add to the groupModel code examples section.
From:
Code: [Select]
Get or set the groupModel option, after initialization:

//getter
var groupModel = grid.option( "groupModel" );
 
//setter
//group by ShipCountry and keep it collapsed.
grid.Group()option({
    dataIndx: ['ShipCountry'],
    collapsed: [ true ]
});

To:
Code: [Select]
Get or set the groupModel option, after initialization:

//getter
var groupModel = grid.option( "groupModel" );
 
//setter
//group by ShipCountry and keep it collapsed.
grid.Group().option({
    dataIndx: ['ShipCountry'],
    collapsed: [ true ]
});

// Toggle the collapsed state of a group
// by JSON dataIndx
grid.Group().option({
    collapsed: [ !this.option('groupModel.collapsed')[
        this.option('groupModel.dataIndx').indexOf('ShipCountry')
    ] ]
});

// by Array Index
grid.Group().option({
    collapsed: [!this.option('groupModel.collapsed')[0]]
});