@@ -16,24 +16,24 @@ export interface IGridState {
16
16
filtering ?: FilteringExpressionsTree ;
17
17
advancedFiltering ?: FilteringExpressionsTree ;
18
18
sorting ?: ISortingExpression [ ] ;
19
- groupby ?: IGroupingExpression [ ] ;
19
+ groupBy ?: IGroupingExpression [ ] ;
20
20
paging ?: IPagingState ;
21
21
cellSelection ?: any [ ] ;
22
22
rowSelection ?: any [ ] ;
23
23
}
24
24
25
- interface IGridStateOptions {
25
+ export interface IGridStateOptions {
26
26
columns ?: boolean ;
27
27
filtering ?: boolean ;
28
28
advancedFiltering ?: boolean ;
29
29
sorting ?: boolean ;
30
- groupby ?: boolean ;
30
+ groupBy ?: boolean ;
31
31
paging ?: boolean ;
32
32
cellSelection ?: boolean ;
33
33
rowSelection ?: boolean ;
34
34
}
35
35
36
- interface IColumnState {
36
+ export interface IColumnState {
37
37
pinned : boolean ;
38
38
sortable : boolean ;
39
39
filterable : boolean ;
@@ -50,16 +50,14 @@ interface IColumnState {
50
50
resizable : boolean ;
51
51
}
52
52
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' ;
63
61
64
62
@Directive ( {
65
63
selector : '[igxGridState]'
@@ -71,7 +69,7 @@ export class IgxGridStateDirective {
71
69
filtering : true ,
72
70
advancedFiltering : true ,
73
71
sorting : true ,
74
- groupby : true ,
72
+ groupBy : true ,
75
73
paging : true ,
76
74
cellSelection : true ,
77
75
rowSelection : true
@@ -99,18 +97,20 @@ export class IgxGridStateDirective {
99
97
Object . assign ( this . _options , value ) ;
100
98
}
101
99
100
+ /**
101
+ * @hidden
102
+ */
102
103
constructor ( @Inject ( INTERFACE_TOKEN ) @Self ( ) @Optional ( ) private grid ) { }
103
104
104
105
/**
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
108
109
* ```html
109
110
* <igx-grid [igxGridState]="options"></igx-grid>
110
111
* ```
111
112
* ```typescript
112
113
* @ViewChild (IgxGridStateDirective, { static: true }) public state;
113
- * const gridState = window.localStorage.getItem(key);
114
114
* this.state.setState(gridState);
115
115
* ```
116
116
*/
@@ -119,14 +119,14 @@ export class IgxGridStateDirective {
119
119
state = JSON . parse ( state as string , this . parseCallback ) as string ;
120
120
}
121
121
this . state = state as IGridState ;
122
- this . restoreGridState ( this . state ) ;
122
+ this . restoreGridState ( ) ;
123
123
}
124
124
125
125
/**
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 .
130
130
* ```html
131
131
* <igx-grid [igxGridState]="options"></igx-grid>
132
132
* ```
@@ -158,11 +158,13 @@ export class IgxGridStateDirective {
158
158
}
159
159
160
160
/**
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 .
162
162
*/
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
+ }
166
168
}
167
169
}
168
170
@@ -171,36 +173,36 @@ export class IgxGridStateDirective {
171
173
*/
172
174
private restoreFeature ( feature : string , state : any ) {
173
175
switch ( feature ) {
174
- case ACTION_COLUMNS : {
176
+ case COLUMNS : {
175
177
this . restoreColumns ( state ) ;
176
178
break ;
177
179
}
178
- case ACTION_FILTERING : {
180
+ case FILTERING : {
179
181
this . restoreFiltering ( state ) ;
180
182
break ;
181
183
}
182
- case ACTION_ADVANCED_FILTERING : {
183
- state = this . restoreAdvancedFiltering ( state ) ;
184
+ case ADVANCED_FILTERING : {
185
+ this . restoreAdvancedFiltering ( state ) ;
184
186
break ;
185
187
}
186
- case ACTION_SORTING : {
188
+ case SORTING : {
187
189
this . restoreSorting ( state ) ;
188
190
break ;
189
191
}
190
- case ACTION_GROUPBY : {
192
+ case GROUPBY : {
191
193
this . restoreGroupBy ( state ) ;
192
194
break ;
193
195
}
194
- case ACTION_PAGING : {
196
+ case PAGING : {
195
197
this . restorePaging ( state ) ;
196
198
break ;
197
199
}
198
- case ACTION_ROW_SELECTION : {
199
- state = this . restoreRowSelection ( state ) ;
200
+ case ROW_SELECTION : {
201
+ this . restoreRowSelection ( state ) ;
200
202
break ;
201
203
}
202
- case ACTION_CELL_SELECTION : {
203
- state = this . restoreCellSelection ( state ) ;
204
+ case CELL_SELECTION : {
205
+ this . restoreCellSelection ( state ) ;
204
206
break ;
205
207
}
206
208
}
@@ -230,35 +232,35 @@ export class IgxGridStateDirective {
230
232
private getGridFeature ( feature : string ) {
231
233
let state = null ;
232
234
switch ( feature ) {
233
- case ACTION_COLUMNS : {
235
+ case COLUMNS : {
234
236
state = this . getColumns ( ) ;
235
237
break ;
236
238
}
237
- case ACTION_FILTERING : {
239
+ case FILTERING : {
238
240
state = this . getFiltering ( ) ;
239
241
break ;
240
242
}
241
- case ACTION_ADVANCED_FILTERING : {
243
+ case ADVANCED_FILTERING : {
242
244
state = this . getAdvancedFiltering ( ) ;
243
245
break ;
244
246
}
245
- case ACTION_SORTING : {
247
+ case SORTING : {
246
248
state = this . getSorting ( ) ;
247
249
break ;
248
250
}
249
- case ACTION_GROUPBY : {
251
+ case GROUPBY : {
250
252
state = this . getGroupBy ( ) ;
251
253
break ;
252
254
}
253
- case ACTION_PAGING : {
255
+ case PAGING : {
254
256
state = this . getPaging ( ) ;
255
257
break ;
256
258
}
257
- case ACTION_ROW_SELECTION : {
259
+ case ROW_SELECTION : {
258
260
state = this . getRowSelection ( ) ;
259
261
break ;
260
262
}
261
- case ACTION_CELL_SELECTION : {
263
+ case CELL_SELECTION : {
262
264
state = this . getCellSelection ( ) ;
263
265
break ;
264
266
}
@@ -312,7 +314,7 @@ export class IgxGridStateDirective {
312
314
313
315
private getGroupBy ( ) {
314
316
const groupingState = this . grid . groupingExpressions ;
315
- return { groupby : groupingState } ;
317
+ return { groupBy : groupingState } ;
316
318
}
317
319
318
320
private getRowSelection ( ) {
@@ -447,7 +449,7 @@ export class IgxGridStateDirective {
447
449
if ( this . grid . columnList . length > 0 ) {
448
450
dataType = this . grid . columnList . find ( c => c . field === expr . fieldName ) . dataType ;
449
451
} 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 ;
451
453
}
452
454
expr . condition = this . generateFilteringCondition ( dataType , expr . condition . name ) ;
453
455
expr . searchVal = ( dataType === 'date' ) ? new Date ( Date . parse ( expr . searchVal ) ) : expr . searchVal ;
0 commit comments