Skip to content

Commit c420e14

Browse files
committed
feat(grid): Fix bug in ESF export interfaces #5460
1 parent 8a993e2 commit c420e14

File tree

2 files changed

+57
-59
lines changed

2 files changed

+57
-59
lines changed

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

+51-49
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ export interface IGridState {
1616
filtering?: FilteringExpressionsTree;
1717
advancedFiltering?: FilteringExpressionsTree;
1818
sorting?: ISortingExpression[];
19-
groupby?: IGroupingExpression[];
19+
groupBy?: IGroupingExpression[];
2020
paging?: IPagingState;
2121
cellSelection?: any[];
2222
rowSelection?: any[];
2323
}
2424

25-
interface IGridStateOptions {
25+
export interface IGridStateOptions {
2626
columns?: boolean;
2727
filtering?: boolean;
2828
advancedFiltering?: boolean;
2929
sorting?: boolean;
30-
groupby?: boolean;
30+
groupBy?: boolean;
3131
paging?: boolean;
3232
cellSelection?: boolean;
3333
rowSelection?: boolean;
3434
}
3535

36-
interface IColumnState {
36+
export interface IColumnState {
3737
pinned: boolean;
3838
sortable: boolean;
3939
filterable: boolean;
@@ -50,16 +50,14 @@ interface IColumnState {
5050
resizable: boolean;
5151
}
5252

53-
// TODO Collapsible column groups
54-
55-
const ACTION_COLUMNS = 'columns';
56-
const ACTION_FILTERING = 'filtering';
57-
const ACTION_ADVANCED_FILTERING = 'advancedFiltering';
58-
const ACTION_SORTING = 'sorting';
59-
const ACTION_GROUPBY = 'groupby';
60-
const ACTION_PAGING = 'paging';
61-
const ACTION_ROW_SELECTION = 'rowSelection';
62-
const ACTION_CELL_SELECTION = 'cellSelection';
53+
const COLUMNS = 'columns';
54+
const FILTERING = 'filtering';
55+
const ADVANCED_FILTERING = 'advancedFiltering';
56+
const SORTING = 'sorting';
57+
const GROUPBY = 'groupBy';
58+
const PAGING = 'paging';
59+
const ROW_SELECTION = 'rowSelection';
60+
const CELL_SELECTION = 'cellSelection';
6361

6462
@Directive({
6563
selector: '[igxGridState]'
@@ -71,7 +69,7 @@ export class IgxGridStateDirective {
7169
filtering: true,
7270
advancedFiltering: true,
7371
sorting: true,
74-
groupby: true,
72+
groupBy: true,
7573
paging: true,
7674
cellSelection: true,
7775
rowSelection: true
@@ -99,18 +97,20 @@ export class IgxGridStateDirective {
9997
Object.assign(this._options, value);
10098
}
10199

100+
/**
101+
* @hidden
102+
*/
102103
constructor(@Inject(INTERFACE_TOKEN) @Self() @Optional() private grid) { }
103104

104105
/**
105-
* Sets the state of a feature or states of all grid features, depending on the state object passed as an argument.
106-
* Pass an IGridState object to set the state for all features, or IPagingState object to set the paging state only.
107-
* returns an object containing all grid features states that are enabled through the `options` property.
106+
* Restores grid features' state based on the IGridState object passed as an argument.
107+
* @param IGridState object to restore state from.
108+
* @returns
108109
* ```html
109110
* <igx-grid [igxGridState]="options"></igx-grid>
110111
* ```
111112
* ```typescript
112113
* @ViewChild(IgxGridStateDirective, { static: true }) public state;
113-
* const gridState = window.localStorage.getItem(key);
114114
* this.state.setState(gridState);
115115
* ```
116116
*/
@@ -119,14 +119,14 @@ export class IgxGridStateDirective {
119119
state = JSON.parse(state as string, this.parseCallback) as string;
120120
}
121121
this.state = state as IGridState;
122-
this.restoreGridState(this.state);
122+
this.restoreGridState();
123123
}
124124

125125
/**
126-
* Gets the state of a feature or states of all grid features.
127-
* If a feature name is not passed as an argument,
128-
* returns an object containing all grid features states that are enabled through the `options` property.
129-
* The optional `serialize` argument determines whether the returned object will be serialized to a JSON string. Default value is false.
126+
* Gets the state of a feature or states of all grid features, unless a certain feature is disabled through the `options` property.
127+
* @param `serialize` determines whether the returned object will be serialized to JSON string. Default value is false.
128+
* @param `feature` string or array of strings determining the features which state to retrieve. If skipped, returns all.
129+
* @returns Returns the serialized to JSON string IGridState object, or the non-serialized IGridState object.
130130
* ```html
131131
* <igx-grid [igxGridState]="options"></igx-grid>
132132
* ```
@@ -158,11 +158,13 @@ export class IgxGridStateDirective {
158158
}
159159

160160
/**
161-
* Helper method that creates a new array with the current grid columns.
161+
* The method that calls corresponding methods to restore feature from this.state object.
162162
*/
163-
public restoreGridState(state) {
164-
for (const key of Object.keys(state)) {
165-
this.restoreFeature(key, state[key]);
163+
private restoreGridState() {
164+
for (const key of Object.keys(this.state)) {
165+
if (this.state[key]) {
166+
this.restoreFeature(key, this.state[key]);
167+
}
166168
}
167169
}
168170

@@ -171,36 +173,36 @@ export class IgxGridStateDirective {
171173
*/
172174
private restoreFeature(feature: string, state: any) {
173175
switch (feature) {
174-
case ACTION_COLUMNS: {
176+
case COLUMNS: {
175177
this.restoreColumns(state);
176178
break;
177179
}
178-
case ACTION_FILTERING: {
180+
case FILTERING: {
179181
this.restoreFiltering(state);
180182
break;
181183
}
182-
case ACTION_ADVANCED_FILTERING: {
183-
state = this.restoreAdvancedFiltering(state);
184+
case ADVANCED_FILTERING: {
185+
this.restoreAdvancedFiltering(state);
184186
break;
185187
}
186-
case ACTION_SORTING: {
188+
case SORTING: {
187189
this.restoreSorting(state);
188190
break;
189191
}
190-
case ACTION_GROUPBY: {
192+
case GROUPBY: {
191193
this.restoreGroupBy(state);
192194
break;
193195
}
194-
case ACTION_PAGING: {
196+
case PAGING: {
195197
this.restorePaging(state);
196198
break;
197199
}
198-
case ACTION_ROW_SELECTION: {
199-
state = this.restoreRowSelection(state);
200+
case ROW_SELECTION: {
201+
this.restoreRowSelection(state);
200202
break;
201203
}
202-
case ACTION_CELL_SELECTION: {
203-
state = this.restoreCellSelection(state);
204+
case CELL_SELECTION: {
205+
this.restoreCellSelection(state);
204206
break;
205207
}
206208
}
@@ -230,35 +232,35 @@ export class IgxGridStateDirective {
230232
private getGridFeature(feature: string) {
231233
let state = null;
232234
switch (feature) {
233-
case ACTION_COLUMNS: {
235+
case COLUMNS: {
234236
state = this.getColumns();
235237
break;
236238
}
237-
case ACTION_FILTERING: {
239+
case FILTERING: {
238240
state = this.getFiltering();
239241
break;
240242
}
241-
case ACTION_ADVANCED_FILTERING: {
243+
case ADVANCED_FILTERING: {
242244
state = this.getAdvancedFiltering();
243245
break;
244246
}
245-
case ACTION_SORTING: {
247+
case SORTING: {
246248
state = this.getSorting();
247249
break;
248250
}
249-
case ACTION_GROUPBY: {
251+
case GROUPBY: {
250252
state = this.getGroupBy();
251253
break;
252254
}
253-
case ACTION_PAGING: {
255+
case PAGING: {
254256
state = this.getPaging();
255257
break;
256258
}
257-
case ACTION_ROW_SELECTION: {
259+
case ROW_SELECTION: {
258260
state = this.getRowSelection();
259261
break;
260262
}
261-
case ACTION_CELL_SELECTION: {
263+
case CELL_SELECTION: {
262264
state = this.getCellSelection();
263265
break;
264266
}
@@ -312,7 +314,7 @@ export class IgxGridStateDirective {
312314

313315
private getGroupBy() {
314316
const groupingState = this.grid.groupingExpressions;
315-
return { groupby: groupingState };
317+
return { groupBy: groupingState };
316318
}
317319

318320
private getRowSelection() {
@@ -447,7 +449,7 @@ export class IgxGridStateDirective {
447449
if (this.grid.columnList.length > 0) {
448450
dataType = this.grid.columnList.find(c => c.field === expr.fieldName).dataType;
449451
} else {
450-
dataType = this.state[ACTION_COLUMNS].find(c => c.field === expr.fieldName).dataType;
452+
dataType = this.state[COLUMNS].find(c => c.field === expr.fieldName).dataType;
451453
}
452454
expr.condition = this.generateFilteringCondition(dataType, expr.condition.name);
453455
expr.searchVal = (dataType === 'date') ? new Date(Date.parse(expr.searchVal)) : expr.searchVal;

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

+6-10
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
7575
this.router.events.pipe(take(1)).subscribe((event: NavigationStart) => {
7676
this.saveGridState();
7777
});
78-
79-
// this.restoreGridState();
8078
}
8179

8280
public ngAfterViewInit() {
@@ -92,6 +90,8 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
9290
// gridFilteringExpressionsTree.filteringOperands.push(productFilteringExpressionsTree);
9391

9492
// this.grid.filteringExpressionsTree = gridFilteringExpressionsTree;
93+
// this.restoreGridState();
94+
9595
}
9696

9797
public saveGridState() {
@@ -128,7 +128,7 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
128128
let state = window.localStorage.getItem(this.stateKey);
129129
state = JSON.parse(state)['filtering'];
130130
if (state) {
131-
this.state.setState({ filtering: state, columns: this.getColumnsState() });
131+
this.state.setState({ filtering: state });
132132
}
133133
}
134134

@@ -137,7 +137,7 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
137137
let state = window.localStorage.getItem(this.stateKey);
138138
state = JSON.parse(state)['advancedFiltering'];
139139
if (state) {
140-
this.state.setState({ advancedFiltering: state, columns: this.getColumnsState() });
140+
this.state.setState({ advancedFiltering: state });
141141
}
142142
}
143143

@@ -151,9 +151,9 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
151151

152152
public restoreGroupby() {
153153
let state = window.localStorage.getItem(this.stateKey);
154-
state = JSON.parse(state)['groupby'];
154+
state = JSON.parse(state)['groupBy'];
155155
if (state) {
156-
this.state.setState({ groupby: state });
156+
this.state.setState({ groupBy: state });
157157
}
158158
}
159159

@@ -196,10 +196,6 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
196196
this.selectionMode = this.selectionModes[args.index].label;
197197
}
198198

199-
public onSerializeChange(event: any) {
200-
// this.serialize = !!event.checked;
201-
}
202-
203199
public clearStorage(toast: IgxToastComponent) {
204200
window.localStorage.removeItem(this.stateKey);
205201
}

0 commit comments

Comments
 (0)