@@ -18,7 +18,7 @@ import { GridSelectionRange } from './common/types';
1818import { CustomFilter } from '../test-utils/grid-samples.spec' ;
1919import { IgxPaginatorComponent } from '../paginator/paginator.component' ;
2020import { NgFor } from '@angular/common' ;
21- import { IgxColumnComponent , IgxGridDetailTemplateDirective } from './public_api' ;
21+ import { IgxColumnComponent , IgxColumnGroupComponent , IgxGridDetailTemplateDirective } from './public_api' ;
2222
2323/* eslint-disable max-len */
2424describe ( 'IgxGridState - input properties #grid' , ( ) => {
@@ -417,6 +417,33 @@ describe('IgxGridState - input properties #grid', () => {
417417 HelperFunctions . verifyColumns ( columnsStateObject . columns , gridState ) ;
418418 } ) ;
419419
420+ it ( 'setState should correctly restore grid columns state properties: collapsible and expanded' , ( ) => {
421+ const fix = TestBed . createComponent ( CollapsibleColumnGroupTestComponent ) ;
422+ fix . detectChanges ( ) ;
423+ const state = fix . componentInstance . state ;
424+ const grid = fix . componentInstance . grid ;
425+ /* eslint-disable max-len */
426+ const initialState = '{"columns":[{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":false,"dataType":"string","hasSummary":false,"field":"ID","width":"100px","header":"","resizable":false,"searchable":true,"selectable":true,"parent":null,"columnGroup":false,"disableHiding":false,"disablePinning":false},{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":false,"dataType":"string","hasSummary":false,"width":"100px","header":"Address Information","resizable":false,"searchable":true,"selectable":true,"parent":null,"columnGroup":true,"disableHiding":false,"disablePinning":false,"collapsible":true,"expanded":true},{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":true,"dataType":"string","hasSummary":false,"field":"City","width":"100px","header":"","resizable":false,"searchable":true,"selectable":true,"parent":"Address Information","columnGroup":false,"disableHiding":false,"disablePinning":false,"visibleWhenCollapsed":true},{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":false,"dataType":"string","hasSummary":false,"field":"Address","width":"100px","header":"","resizable":false,"searchable":true,"selectable":true,"parent":"Address Information","columnGroup":false,"disableHiding":false,"disablePinning":false,"visibleWhenCollapsed":false}]}'
427+ const newState = `{"columns":[{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":false,"dataType":"string","hasSummary":false,"field":"ID","width":"100px","header":"","resizable":false,"searchable":true,"selectable":true,"parent":null,"columnGroup":false,"disableHiding":false,"disablePinning":false},{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":false,"dataType":"string","hasSummary":false,"width":"100px","header":"Address Information","resizable":false,"searchable":true,"selectable":true,"parent":null,"columnGroup":true,"disableHiding":false,"disablePinning":false,"collapsible":true,"expanded":false},{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":true,"dataType":"string","hasSummary":false,"field":"City","width":"100px","header":"","resizable":false,"searchable":true,"selectable":true,"parent":"Address Information","columnGroup":false,"disableHiding":false,"disablePinning":false,"visibleWhenCollapsed":true},{"pinned":false,"sortable":false,"filterable":true,"editable":false,"sortingIgnoreCase":true,"filteringIgnoreCase":true,"headerClasses":"","headerGroupClasses":"","groupable":false,"movable":false,"hidden":false,"dataType":"string","hasSummary":false,"field":"Address","width":"100px","header":"","resizable":false,"searchable":true,"selectable":true,"parent":"Address Information","columnGroup":false,"disableHiding":false,"disablePinning":false,"visibleWhenCollapsed":false}]}`
428+ /* eslint-enable max-len */
429+ const columnsStateObject = JSON . parse ( newState ) ;
430+ let gridState = state . getState ( true , 'columns' ) ;
431+ expect ( gridState ) . toBe ( initialState ) ;
432+ // 1. initial state collapsible:true, expanded: true;
433+ // 2. new state collapsible:true, expanded: false after restoration
434+
435+ state . setState ( columnsStateObject ) ; // set new state - resored state
436+ gridState = state . getState ( false , 'columns' ) as IGridState ;
437+ HelperFunctions . verifyColumns ( columnsStateObject . columns , gridState ) ;
438+ gridState = state . getState ( true , 'columns' ) ;
439+ fix . detectChanges ( ) ;
440+ expect ( gridState ) . toBe ( newState ) ;
441+
442+ const addressInfoGroup = grid . columns . find ( c => c . header === "Address Information" ) ;
443+ expect ( addressInfoGroup . collapsible ) . toBe ( true ) ;
444+ expect ( addressInfoGroup . expanded ) . toBe ( false ) ;
445+ } ) ;
446+
420447 it ( 'setState should correctly restore grid paging state from string' , ( ) => {
421448 const fix = TestBed . createComponent ( IgxGridStateComponent ) ;
422449 fix . detectChanges ( ) ;
@@ -867,5 +894,26 @@ export class IgxGridStateWithDetailsComponent {
867894
868895 public data = SampleTestData . foodProductData ( ) ;
869896}
897+
898+ @Component ( {
899+ template : `
900+ <igx-grid #grid [data]="data" igxGridState height="500px" width="1300px" columnWidth="100px">
901+ <igx-column field="ID"></igx-column>
902+ <igx-column-group header="Address Information" [collapsible]="true">
903+ <igx-column field="City" [visibleWhenCollapsed]="true"></igx-column>
904+ <igx-column field="Address" [visibleWhenCollapsed]="false"></igx-column>
905+ </igx-column-group>
906+ </igx-grid>
907+ ` ,
908+ standalone : true ,
909+ imports : [ IgxGridComponent , IgxColumnComponent , IgxColumnGroupComponent , IgxGridStateDirective , NgFor ]
910+ } )
911+ export class CollapsibleColumnGroupTestComponent {
912+ @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
913+ public grid : IgxGridComponent ;
914+ @ViewChild ( IgxGridStateDirective , { static : true } )
915+ public state : IgxGridStateDirective ;
916+ public data = SampleTestData . contactInfoDataFull ( ) ;
917+ }
870918/* eslint-enable max-len */
871919
0 commit comments