Web Components Grid の Ignite UI for Web Components 状態保持を使用すると、開発者はグリッドの状態を簡単に保存および復元できます。IgcGridState が Web Components IgcGridComponent に適用されると、GetState、GetStateAsString、ApplyState および ApplyStateFromString メソッドが公開され、開発者はこれを使用して、あらゆるシナリオで状態の永続化を実現できます。
var gridState = document.getElementById('gridState') as IgcGridStateComponent;
// get an `IgcGridStateInfo` object, containing all features original state objects, as returned by the grid public APIconst state: IgcGridStateInfo = gridState.getState();
// get all features` state in a serialized JSON stringconst stateString: string = gridState.getStateAsString();
// get the sorting and filtering expressionsconst sortingFilteringStates: IgcGridStateInfo = gridState.getState(['sorting', 'filtering']);
typescript
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="sampleContainer"><divclass="container horizontal"><igc-buttonid="restoreState"variant="contained"><igc-iconname="restore"collection="material"></igc-icon>
Restore
</igc-button><igc-buttonid="saveState"variant="contained"><igc-iconname="save"collection="material"></igc-icon>
Save
</igc-button><igc-buttonid="resetState"variant="contained"><igc-iconname="clear"collection="material"></igc-icon>
Reset
</igc-button><igc-buttonid="leavePage"variant="contained"><igc-iconname="forward"collection="material"></igc-icon>
Leave
</igc-button><igc-buttonid="clearStorage"variant="contained"><igc-iconname="delete"collection="material"></igc-icon>
Clear
</igc-button><igc-buttonid="reloadPage"variant="contained"><igc-iconname="refresh"collection="material"></igc-icon>
Reload
</igc-button></div><divclass="container horizontal"><ul><li>Clicking the SAVE button or leaving the page <aid="leaveLink"href="./grids/grid/state-persistence-about"><strong>here</strong></a> will save grid state to localStorage.</li><li>Use the control buttons to SAVE / RESTORE / RESET / DELETE / grid state or LEAVE the page.</li><li>Select/Deselect checkboxes to control saving / restoring feature state.</li></ul></div><divclass="container horizontal"><igc-checkboxid="allFeatures"checked>All Features</igc-checkbox><igc-checkboxid="advancedFiltering"checked>Adv. Filtering</igc-checkbox><igc-checkboxid="cellSelection"checked>Cell Selection</igc-checkbox><igc-checkboxid="columns"checked>Columns</igc-checkbox><igc-checkboxid="columnSelection"checked>Col Selection</igc-checkbox><igc-checkboxid="expansion"checked>Expansion</igc-checkbox><igc-checkboxid="filtering"checked>Filtering</igc-checkbox><igc-checkboxid="paging"checked>Paging</igc-checkbox><igc-checkboxid="rowPinning"checked>Row Pinning</igc-checkbox><igc-checkboxid="rowSelection"checked>Row Selection</igc-checkbox><igc-checkboxid="sorting"checked>Sorting</igc-checkbox><igc-checkboxid="groupBy"checked>GroupBy</igc-checkbox><igc-checkboxid="moving"checked>Moving</igc-checkbox></div><igc-gridid="grid"name="grid"primary-key="ID"width="98%"height="500px"auto-generate="false"moving="true"allow-filtering="true"><igc-grid-stateid="gridState"></igc-grid-state><igc-grid-toolbar><igc-grid-toolbar-actions><igc-grid-toolbar-hiding></igc-grid-toolbar-hiding><igc-grid-toolbar-pinning></igc-grid-toolbar-pinning></igc-grid-toolbar-actions></igc-grid-toolbar><igc-action-strip><igc-grid-pinning-actions></igc-grid-pinning-actions></igc-action-strip><igc-paginator></igc-paginator><igc-columnfield="ID"header="ID"sortable="true"filterable="true"pinned="true"></igc-column><igc-columnfield="ContactName"header="Contact Name"sortable="true"filterable="true"pinned="true"></igc-column><igc-columnfield="ContactTitle"header="Contact Title"sortable="true"filterable="true"></igc-column><igc-columnfield="CompanyName"header="Company Name"sortable="true"filterable="true"></igc-column><igc-columnfield="Country"header="Country"sortable="true"filterable="true"groupable="true"></igc-column><igc-columnfield="City"header="City"sortable="true"filterable="true"groupable="true"></igc-column><igc-columnfield="Address"header="Address"sortable="true"filterable="true"groupable="true" ></igc-column><igc-columnfield="PostalCode"header="Postal Code"sortable="true"filterable="true"groupable="true"></igc-column></igc-grid></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html