Skip to content

Commit 6bac4dc

Browse files
committed
feat(grid): export state directive in index #5460
1 parent 5b9eed8 commit 6bac4dc

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

Diff for: projects/igniteui-angular/src/lib/grids/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './grid-common.module';
1010
export { IColumnVisibilityChangedEventArgs } from './hiding/column-hiding-item.directive';
1111
export * from './hiding/column-hiding.component';
1212
export * from './pinning/column-pinning.component';
13+
export * from './state.directive';

Diff for: src/app/grid-state/grid-state.component.ts

+36-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
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';
34
import { employeesData } from './localData';
45
import { take } from 'rxjs/operators';
56
import { NavigationStart, Router } from '@angular/router';
@@ -43,8 +44,8 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
4344
columns: true
4445
};
4546

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;
4849

4950
public initialColumns: IColumnState[] = [
5051
// tslint:disable:max-line-length
@@ -125,67 +126,73 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
125126
}
126127

127128
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);
132134
}
133135
}
134136

135137
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);
141143
}
142144
}
143145

144146
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;
147149
if (state) {
148-
this.state.setState({ sorting: state });
150+
const gridSortingState: IGridState = { sorting: sortingState};
151+
this.state.setState(gridSortingState);
149152
}
150153
}
151154

152155
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;
155158
if (state) {
156-
this.state.setState({ groupBy: state });
159+
const gridGroupiByState: IGridState = { groupBy: groupByState};
160+
this.state.setState(gridGroupiByState);
157161
}
158162
}
159163

160164
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;
163167
if (state) {
164-
this.state.setState({ rowSelection: state });
168+
const gridRowSelectionState: IGridState = { rowSelection: rowSelectionState };
169+
this.state.setState(gridRowSelectionState);
165170
}
166171
}
167172

168173
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;
171176
if (state) {
172-
this.state.setState({ cellSelection: state });
177+
const gridCellSelectionState: IGridState = { cellSelection: cellSelectionState };
178+
this.state.setState(gridCellSelectionState);
173179
}
174180
}
175181

176182
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;
179185
if (state) {
180-
this.state.setState({ paging: state });
186+
const gridPagingState: IGridState = { paging: pagingState };
187+
this.state.setState(gridPagingState);
181188
}
182189
}
183190

184191
public resetGridState() {
185192
this.grid.filteringExpressionsTree = new FilteringExpressionsTree(FilteringLogic.And);
186-
this.grid.advancedFilteringExpressionTree = new FilteringExpressionsTree(FilteringLogic.And);
193+
this.grid.advancedFilteringExpressionsTree = new FilteringExpressionsTree(FilteringLogic.And);
187194
this.grid.sortingExpressions = [];
188-
this.grid.groupbyExpressions = [];
195+
this.grid.groupingExpressions = [];
189196
}
190197

191198
public onChange(event: any, action: string) {

0 commit comments

Comments
 (0)