@@ -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' , ( ) => {
@@ -397,6 +397,32 @@ describe('IgxGridState - input properties #grid', () => {
397397 expect ( grid . columnInit . emit ) . toHaveBeenCalledTimes ( columnsStateObject . columns . length ) ;
398398 } ) ;
399399
400+ it ( 'setState should correctly restore grid columns state properties: collapsible and expanded' , ( ) => {
401+ const fix = TestBed . createComponent ( CollapsibleColumnGroupTestComponent ) ;
402+ fix . detectChanges ( ) ;
403+ const state = fix . componentInstance . state ;
404+ const grid = fix . componentInstance . grid ;
405+ /* eslint-disable max-len */
406+ 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}]}'
407+ 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}]}`
408+ /* eslint-enable max-len */
409+ const columnsStateObject = JSON . parse ( newState ) ;
410+ let gridState = state . getState ( true , 'columns' ) ;
411+ expect ( gridState ) . toBe ( initialState ) ;
412+ // 1. initial state collapsible:true, expanded: true;
413+ // 2. new state collapsible:true, expanded: false after restoration
414+
415+ state . setState ( columnsStateObject ) ; // set new state - resored state
416+ gridState = state . getState ( false , 'columns' ) as IGridState ;
417+ HelperFunctions . verifyColumns ( columnsStateObject . columns , gridState ) ;
418+ gridState = state . getState ( true , 'columns' ) ;
419+ fix . detectChanges ( ) ;
420+ expect ( gridState ) . toBe ( newState ) ;
421+
422+ const addressInfoGroup = grid . columns . find ( c => c . header === "Address Information" ) ;
423+ expect ( addressInfoGroup . collapsible ) . toBe ( true ) ;
424+ expect ( addressInfoGroup . expanded ) . toBe ( false ) ;
425+ } ) ;
400426 it ( 'setState should correctly restore grid paging state from string' , ( ) => {
401427 const fix = TestBed . createComponent ( IgxGridStateComponent ) ;
402428 fix . detectChanges ( ) ;
@@ -847,5 +873,26 @@ export class IgxGridStateWithDetailsComponent {
847873
848874 public data = SampleTestData . foodProductData ( ) ;
849875}
876+
877+ @Component ( {
878+ template : `
879+ <igx-grid #grid [data]="data" igxGridState height="500px" width="1300px" columnWidth="100px">
880+ <igx-column field="ID"></igx-column>
881+ <igx-column-group header="Address Information" [collapsible]="true">
882+ <igx-column field="City" [visibleWhenCollapsed]="true"></igx-column>
883+ <igx-column field="Address" [visibleWhenCollapsed]="false"></igx-column>
884+ </igx-column-group>
885+ </igx-grid>
886+ ` ,
887+ standalone : true ,
888+ imports : [ IgxGridComponent , IgxColumnComponent , IgxColumnGroupComponent , IgxGridStateDirective , NgFor ]
889+ } )
890+ export class CollapsibleColumnGroupTestComponent {
891+ @ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
892+ public grid : IgxGridComponent ;
893+ @ViewChild ( IgxGridStateDirective , { static : true } )
894+ public state : IgxGridStateDirective ;
895+ public data = SampleTestData . contactInfoDataFull ( ) ;
896+ }
850897/* eslint-enable max-len */
851898
0 commit comments