@@ -287,7 +287,7 @@ <h3 class="ig-typography__h6">Flat Grid (MRL column layout)</h3>
287287 </ script >
288288 <!-- END IgxTreeGridComponent -->
289289
290- < igc-hierarchical-grid id ="hgrid1 " moving ="true " allow-filtering ="true " filter-mode ="excelStyleFilter " display-density ="compact ">
290+ < igc-hierarchical-grid id ="hgrid1 " primary-key =" ProjectId " moving ="true " allow-filtering ="true " filter-mode ="excelStyleFilter " display-density ="compact ">
291291 < igc-grid-state id ="state2 "> </ igc-grid-state >
292292 < igc-column field ="ProjectId " data-type ="number " header ="Project Id " sortable ="true " selectable ="false "> </ igc-column >
293293 < igc-column field ="Name " data-type ="string " header ="Name " sortable ="true " selectable ="false "> </ igc-column >
@@ -315,7 +315,12 @@ <h3 class="ig-typography__h6">Flat Grid (MRL column layout)</h3>
315315 < igc-grid-pinning-actions > </ igc-grid-pinning-actions >
316316 < igc-grid-editing-actions add-row ="true "> </ igc-grid-editing-actions >
317317 </ igc-action-strip >
318+ < igc-grid-state id ="hgridState "> </ igc-grid-state >
318319 </ igc-hierarchical-grid >
320+ < div class ="hgrid1-actions ">
321+ < button id ="saveStateHierarchical "> Save state</ button >
322+ < button id ="restoreStateHierarchical "> Restore</ button >
323+ </ div >
319324
320325 <!-- IgxPivotGridComponent -->
321326 < igc-pivot-grid id ="pivotgrid1 " default-expand-state ="true " row-selection ="single "> </ igc-pivot-grid >
@@ -417,9 +422,27 @@ <h3 class="ig-typography__h6">Flat Grid (MRL column layout)</h3>
417422 import { html } from "/lit-html.js" ;
418423 // jump around vite import analysis with dynamic import url
419424 const hgridData = ( await import ( `/assets/${ 'data' } /projects-hgrid.js` ) ) . default ;
425+ function saveStateHierarchical ( ) {
426+ const stateComponent = document . getElementById ( 'hgridState' ) ;
427+ const stringData = stateComponent . getStateAsString ( ) ;
428+ window . localStorage . setItem ( `hgrid1-state` , stringData ) ;
429+ }
430+
431+ function restoreStateHierarchical ( ) {
432+ const stateComponent = document . getElementById ( 'hgridState' ) ;
433+ const stateData = window . localStorage . getItem ( `hgrid1-state` ) ;
434+ if ( stateData ) {
435+ const obj = JSON . parse ( stateData ) ;
436+ stateComponent . applyState ( obj ) ;
437+ }
438+ }
420439 let hgrid = document . getElementById ( 'hgrid1' ) ;
440+ hgrid . addEventListener ( 'childrenAttached' , ( ) => {
441+ restoreStateHierarchical ( ) ;
442+ } ) ;
421443 hgrid . data = hgridData ;
422-
444+ document . getElementById ( "saveStateHierarchical" ) . addEventListener ( "click" , saveStateHierarchical ) ;
445+ document . getElementById ( "restoreStateHierarchical" ) . addEventListener ( "click" , restoreStateHierarchical ) ;
423446 let developersRowIsland = document . getElementById ( 'DevelopersRowIsland' ) ;
424447 let virtualMachinesRowIsland = document . getElementById ( 'VirtualMachinesRowIsland' ) ;
425448 virtualMachinesRowIsland . paginatorTemplate = ( ctx ) => html `
0 commit comments