@@ -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' , ( ) => {
@@ -416,6 +416,33 @@ describe('IgxGridState - input properties #grid', () => {
416416 HelperFunctions . verifyColumns ( columnsStateObject . columns , gridState ) ;
417417 } ) ;
418418
419+ it ( 'setState should correctly restore grid columns state properties: collapsible and expanded' , ( ) => {
420+ const fix = TestBed . createComponent ( CollapsibleColumnGroupTestComponent ) ;
421+ fix . detectChanges ( ) ;
422+ const state = fix . componentInstance . state ;
423+ const grid = fix . componentInstance . grid ;
424+ /* eslint-disable max-len */
425+ 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}]}'
426+ 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}]}`
427+ /* eslint-enable max-len */
428+ const columnsStateObject = JSON . parse ( newState ) ;
429+ let gridState = state . getState ( true , 'columns' ) ;
430+ expect ( gridState ) . toBe ( initialState ) ;
431+ // 1. initial state collapsible:true, expanded: true;
432+ // 2. new state collapsible:true, expanded: false after restoration
433+
434+ state . setState ( columnsStateObject ) ; // set new state - resored state
435+ gridState = state . getState ( false , 'columns' ) as IGridState ;
436+ HelperFunctions . verifyColumns ( columnsStateObject . columns , gridState ) ;
437+ gridState = state . getState ( true , 'columns' ) ;
438+ fix . detectChanges ( ) ;
439+ expect ( gridState ) . toBe ( newState ) ;
440+
441+ const addressInfoGroup = grid . columns . find ( c => c . header === "Address Information" ) ;
442+ expect ( addressInfoGroup . collapsible ) . toBe ( true ) ;
443+ expect ( addressInfoGroup . expanded ) . toBe ( false ) ;
444+ } ) ;
445+
419446 it ( 'setState should correctly restore grid paging state from string' , ( ) => {
420447 const fix = TestBed . createComponent ( IgxGridStateComponent ) ;
421448 fix . detectChanges ( ) ;
@@ -866,5 +893,26 @@ export class IgxGridStateWithDetailsComponent {
866893
867894 public data = SampleTestData . foodProductData ( ) ;
868895}
896+
897+ @Component ( {
898+ template : `
899+ <igx-grid #grid [data]="data" igxGridState height="500px" width="1300px" columnWidth="100px">
900+ <igx-column field="ID"></igx-column>
901+ <igx-column-group header="Address Information" [collapsible]="true">
902+ <igx-column field="City" [visibleWhenCollapsed]="true"></igx-column>
903+ <igx-column field="Address" [visibleWhenCollapsed]="false"></igx-column>
904+ </igx-column-group>
905+ </igx-grid>
906+ ` ,
907+ standalone : true ,
908+ imports : [ IgxGridComponent , IgxColumnComponent , IgxColumnGroupComponent , IgxGridStateDirective , NgFor ]
909+ } )
910+ export class CollapsibleColumnGroupTestComponent {
911+ @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
912+ public grid : IgxGridComponent ;
913+ @ViewChild ( IgxGridStateDirective , { static : true } )
914+ public state : IgxGridStateDirective ;
915+ public data = SampleTestData . contactInfoDataFull ( ) ;
916+ }
869917/* eslint-enable max-len */
870918
0 commit comments