@@ -23,9 +23,39 @@ import { flatten } from '../../core/utils';
2323 template : ``
2424} )
2525export class IgxColumnGroupComponent extends IgxColumnComponent implements AfterContentInit {
26+ private _collapsible = false ;
27+ private _expanded = true ;
2628
2729 @ContentChildren ( IgxColumnComponent , { read : IgxColumnComponent } )
2830 children = new QueryList < IgxColumnComponent > ( ) ;
31+
32+ @Input ( )
33+ public set collapsible ( value : boolean ) {
34+ this . _collapsible = value ;
35+ if ( this . children ) {
36+ if ( value ) {
37+ this . setExpandCollapseState ( ) ;
38+ } else {
39+ this . children . forEach ( child => child . hidden = false ) ;
40+ }
41+ }
42+ }
43+ public get collapsible ( ) {
44+ return this . _collapsible ;
45+ }
46+
47+ @Input ( )
48+ public get expanded ( ) {
49+ return this . _expanded ;
50+ }
51+ public set expanded ( value : boolean ) {
52+ this . _expanded = value ;
53+ if ( ! this . collapsible ) { return ; }
54+ if ( ! this . hidden && this . children ) {
55+ this . setExpandCollapseState ( ) ;
56+ }
57+ }
58+
2959 /**
3060 * Gets the column group `summaries`.
3161 * ```typescript
@@ -143,7 +173,14 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
143173 set hidden ( value : boolean ) {
144174 this . _hidden = value ;
145175 this . hiddenChange . emit ( this . _hidden ) ;
146- this . children . forEach ( child => child . hidden = value ) ;
176+ if ( value || ! this . collapsible ) {
177+ this . children . forEach ( child => child . hidden = value ) ;
178+ } else {
179+ this . children . forEach ( c => {
180+ if ( c . openOnGroupCollapsed === undefined ) { c . hidden = false ; return ; }
181+ c . hidden = this . expanded ? c . openOnGroupCollapsed : ! c . openOnGroupCollapsed ;
182+ } ) ;
183+ }
147184 }
148185
149186 /**
@@ -170,6 +207,14 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
170207 this . children . forEach ( child => {
171208 child . parent = this ;
172209 } ) ;
210+ if ( this . collapsible ) {
211+ const cols = this . children . map ( child => child . openOnGroupCollapsed ) ;
212+ if ( ! ( cols . some ( c => c === true ) && cols . some ( c => c === false ) ) ) {
213+ this . collapsible = false ;
214+ return ;
215+ }
216+ this . setExpandCollapseState ( ) ;
217+ }
173218 }
174219 /**
175220 * Returns the children columns collection.
@@ -225,6 +270,12 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
225270
226271 set width ( val ) { }
227272
273+ private setExpandCollapseState ( ) {
274+ this . children . filter ( col => ( col . openOnGroupCollapsed !== undefined ) ) . forEach ( c => {
275+ c . hidden = this . _expanded ? c . openOnGroupCollapsed : ! c . openOnGroupCollapsed ;
276+ } ) ;
277+ }
278+
228279 // constructor(public gridAPI: GridBaseAPIService<IgxGridBaseDirective & IGridDataBindable>, public cdr: ChangeDetectorRef) {
229280 // // D.P. constructor duplication due to es6 compilation, might be obsolete in the future
230281 // super(gridAPI, cdr);
0 commit comments