# Persisting the State of the ExpansionPanel

## Environment

<table>
    <tbody>
	    <tr>
	    	<td>Product</td>
	    	<td>Progress® Kendo UI for Angular ExpansionPanel</td>
	    </tr>
    </tbody>
</table>

## Description

How can I persist the expand and collapse state of the Kendo UI for Angular ExpansionPanel?

## Solution

To persist the expand and collapse state of the Kendo UI for Angular ExpansionPanel, or load its previously stored state, use the following approach:

1. Render the ExpansionPanel components dynamically with the help of a data array that contains an item for every component instance. Configure the data items to include a field for the current expanded state of each ExpansionPanel and bind it to the [expanded](https://www.telerik.com/kendo-angular-ui-develop/components/layout/api/expansionpanelcomponent#expanded) property of the component.

   ```html
   @for (item of items; track item; let i = $index) {
     <kendo-expansionpanel
       [title]="item.country"
       [subtitle]="item.continent"
       [(expanded)]="item.expanded">
       <div class="content">
           <span class="content-text">{{ item.text }}</span>
       </div>
     </kendo-expansionpanel>
   }
   ```

2. Extract the value of the `expanded` field for each item from the array and use a desired caching mechanism to store the obtained values. This example demonstrates how to store the expansion state in the [`LocalStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) of the browser.

   ```ts
   public saveExpansionState(): void {
       const expansionState = this.items.map((item) => item.expanded);

       // Save the expansion state to local storage
       localStorage.setItem('expansionState', JSON.stringify(expansionState));
       this.savedStateExists = true;
   }
   ```

3. Load the previously stored values (if any) and update the expanded state of the corresponding ExpansionPanel items according to these values.

   ```ts
   public loadExpansionState(): void {
       const savedState = localStorage.getItem('expansionState');

       if (savedState) {
           const expansionState = JSON.parse(savedState);

           // Set the expansion state for each item
           this.items.forEach((item, index) => {
               if (expansionState[index] !== undefined) {
                   item.expanded = expansionState[index];
               }
           });
       }
   }
   ```

The following example demonstrates the full implementation of the suggested approach.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/knowledge-base/expansionpanel-persist-state/source.txt)

## See Also

* [Kendo UI for Angular ExpansionPanel Overview](https://www.telerik.com/kendo-angular-ui-develop/components/layout/expansionpanel)
* [Kendo UI for Angular ExpansionPanel Interaction Modes](https://www.telerik.com/kendo-angular-ui-develop/components/layout/expansionpanel/interaction)
* [API Reference of the ExpansionPanel Component](https://www.telerik.com/kendo-angular-ui-develop/components/layout/api/expansionpanelcomponent)
