|
1 | 1 | import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
|
2 |
| -import { IgxToastComponent, IgxGridComponent, FilteringExpressionsTree, FilteringLogic } from 'igniteui-angular'; |
| 2 | +import { IgxToastComponent, IgxGridComponent, FilteringExpressionsTree, FilteringLogic, |
| 3 | + IPagingState, IGroupingExpression, ISortingExpression } from 'igniteui-angular'; |
3 | 4 | import { employeesData } from './localData';
|
4 | 5 | import { take } from 'rxjs/operators';
|
5 | 6 | import { NavigationStart, Router } from '@angular/router';
|
@@ -43,8 +44,8 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
|
43 | 44 | columns: true
|
44 | 45 | };
|
45 | 46 |
|
46 |
| - @ViewChild(IgxGridStateDirective, { static: true }) public state; |
47 |
| - @ViewChild(IgxGridComponent, { static: true }) public grid; |
| 47 | + @ViewChild(IgxGridStateDirective, { static: true }) public state: IgxGridStateDirective; |
| 48 | + @ViewChild(IgxGridComponent, { static: true }) public grid: IgxGridComponent; |
48 | 49 |
|
49 | 50 | public initialColumns: IColumnState[] = [
|
50 | 51 | // tslint:disable:max-line-length
|
@@ -125,67 +126,73 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
|
125 | 126 | }
|
126 | 127 |
|
127 | 128 | public restoreFiltering() {
|
128 |
| - let state = window.localStorage.getItem(this.stateKey); |
129 |
| - state = JSON.parse(state)['filtering']; |
130 |
| - if (state) { |
131 |
| - this.state.setState({ filtering: state }); |
| 129 | + const state = window.localStorage.getItem(this.stateKey); |
| 130 | + const filteringState: FilteringExpressionsTree = JSON.parse(state).filtering; |
| 131 | + if (filteringState) { |
| 132 | + const gridFilteringState: IGridState = { filtering: filteringState}; |
| 133 | + this.state.setState(gridFilteringState); |
132 | 134 | }
|
133 | 135 | }
|
134 | 136 |
|
135 | 137 | public restoreAdvancedFiltering() {
|
136 |
| - this.restoreColumns(); |
137 |
| - let state = window.localStorage.getItem(this.stateKey); |
138 |
| - state = JSON.parse(state)['advancedFiltering']; |
139 |
| - if (state) { |
140 |
| - this.state.setState({ advancedFiltering: state }); |
| 138 | + const state = window.localStorage.getItem(this.stateKey); |
| 139 | + const advFilteringState: FilteringExpressionsTree = JSON.parse(state).advancedFiltering; |
| 140 | + if (advFilteringState) { |
| 141 | + const gridAdvancedFilteringState: IGridState = { advancedFiltering: advFilteringState}; |
| 142 | + this.state.setState(gridAdvancedFilteringState); |
141 | 143 | }
|
142 | 144 | }
|
143 | 145 |
|
144 | 146 | public restoreSorting() {
|
145 |
| - let state = window.localStorage.getItem(this.stateKey); |
146 |
| - state = JSON.parse(state)['sorting']; |
| 147 | + const state = window.localStorage.getItem(this.stateKey); |
| 148 | + const sortingState: ISortingExpression[] = JSON.parse(state).sorting; |
147 | 149 | if (state) {
|
148 |
| - this.state.setState({ sorting: state }); |
| 150 | + const gridSortingState: IGridState = { sorting: sortingState}; |
| 151 | + this.state.setState(gridSortingState); |
149 | 152 | }
|
150 | 153 | }
|
151 | 154 |
|
152 | 155 | public restoreGroupby() {
|
153 |
| - let state = window.localStorage.getItem(this.stateKey); |
154 |
| - state = JSON.parse(state)['groupBy']; |
| 156 | + const state = window.localStorage.getItem(this.stateKey); |
| 157 | + const groupByState: IGroupingExpression[] = JSON.parse(state).groupby; |
155 | 158 | if (state) {
|
156 |
| - this.state.setState({ groupBy: state }); |
| 159 | + const gridGroupiByState: IGridState = { groupBy: groupByState}; |
| 160 | + this.state.setState(gridGroupiByState); |
157 | 161 | }
|
158 | 162 | }
|
159 | 163 |
|
160 | 164 | public restoreRowSelection() {
|
161 |
| - let state = window.localStorage.getItem(this.stateKey); |
162 |
| - state = JSON.parse(state)['rowSelection']; |
| 165 | + const state = window.localStorage.getItem(this.stateKey); |
| 166 | + const rowSelectionState = JSON.parse(state).rowSelection; |
163 | 167 | if (state) {
|
164 |
| - this.state.setState({ rowSelection: state }); |
| 168 | + const gridRowSelectionState: IGridState = { rowSelection: rowSelectionState }; |
| 169 | + this.state.setState(gridRowSelectionState); |
165 | 170 | }
|
166 | 171 | }
|
167 | 172 |
|
168 | 173 | public restoreCellSelection() {
|
169 |
| - let state = window.localStorage.getItem(this.stateKey); |
170 |
| - state = JSON.parse(state)['cellSelection']; |
| 174 | + const state = window.localStorage.getItem(this.stateKey); |
| 175 | + const cellSelectionState = JSON.parse(state).cellSelection; |
171 | 176 | if (state) {
|
172 |
| - this.state.setState({ cellSelection: state }); |
| 177 | + const gridCellSelectionState: IGridState = { cellSelection: cellSelectionState }; |
| 178 | + this.state.setState(gridCellSelectionState); |
173 | 179 | }
|
174 | 180 | }
|
175 | 181 |
|
176 | 182 | public restorePaging() {
|
177 |
| - let state = window.localStorage.getItem(this.stateKey); |
178 |
| - state = JSON.parse(state)['paging']; |
| 183 | + const state = window.localStorage.getItem(this.stateKey); |
| 184 | + const pagingState: IPagingState = JSON.parse(state).paging; |
179 | 185 | if (state) {
|
180 |
| - this.state.setState({ paging: state }); |
| 186 | + const gridPagingState: IGridState = { paging: pagingState }; |
| 187 | + this.state.setState(gridPagingState); |
181 | 188 | }
|
182 | 189 | }
|
183 | 190 |
|
184 | 191 | public resetGridState() {
|
185 | 192 | this.grid.filteringExpressionsTree = new FilteringExpressionsTree(FilteringLogic.And);
|
186 |
| - this.grid.advancedFilteringExpressionTree = new FilteringExpressionsTree(FilteringLogic.And); |
| 193 | + this.grid.advancedFilteringExpressionsTree = new FilteringExpressionsTree(FilteringLogic.And); |
187 | 194 | this.grid.sortingExpressions = [];
|
188 |
| - this.grid.groupbyExpressions = []; |
| 195 | + this.grid.groupingExpressions = []; |
189 | 196 | }
|
190 | 197 |
|
191 | 198 | public onChange(event: any, action: string) {
|
|
0 commit comments