@@ -12,13 +12,14 @@ import { IgxBooleanFilteringOperand, IgxNumberFilteringOperand, IgxDateFiltering
12
12
IgxStringFilteringOperand } from '../data-operations/filtering-condition' ;
13
13
14
14
export interface IGridState {
15
- columns : IColumnState [ ] ;
16
- filtering : FilteringExpressionsTree ;
17
- advancedFiltering : FilteringExpressionsTree ;
18
- sorting : ISortingExpression [ ] ;
19
- groupby : IGroupingExpression [ ] ;
20
- paging : IPagingState ;
21
- selection : any [ ] ;
15
+ columns ?: IColumnState [ ] ;
16
+ filtering ?: FilteringExpressionsTree ;
17
+ advancedFiltering ?: FilteringExpressionsTree ;
18
+ sorting ?: ISortingExpression [ ] ;
19
+ groupby ?: IGroupingExpression [ ] ;
20
+ paging ?: IPagingState ;
21
+ cellSelection ?: any [ ] ;
22
+ rowSelection ?: any [ ] ;
22
23
}
23
24
24
25
interface IGridStateOptions {
@@ -28,7 +29,8 @@ interface IGridStateOptions {
28
29
sorting ?: boolean ;
29
30
groupby ?: boolean ;
30
31
paging ?: boolean ;
31
- selection ?: boolean ;
32
+ cellSelection ?: boolean ;
33
+ rowSelection ?: boolean ;
32
34
}
33
35
34
36
interface IColumnState {
@@ -56,7 +58,8 @@ const ACTION_ADVANCED_FILTERING = 'advancedFiltering';
56
58
const ACTION_SORTING = 'sorting' ;
57
59
const ACTION_GROUPBY = 'groupby' ;
58
60
const ACTION_PAGING = 'paging' ;
59
- const ACTION_SELECTION = 'selection' ;
61
+ const ACTION_ROW_SELECTION = 'rowSelection' ;
62
+ const ACTION_CELL_SELECTION = 'cellSelection' ;
60
63
61
64
@Directive ( {
62
65
selector : '[igxGridState]'
@@ -70,7 +73,8 @@ export class IgxGridStateDirective {
70
73
sorting : true ,
71
74
groupby : true ,
72
75
paging : true ,
73
- selection : true ,
76
+ cellSelection : true ,
77
+ rowSelection : true
74
78
} ;
75
79
76
80
private state : IGridState | IColumnState | IFilteringExpressionsTree |
@@ -110,17 +114,11 @@ export class IgxGridStateDirective {
110
114
* this.state.setState(gridState);
111
115
* ```
112
116
*/
113
- public setState ( state : IGridState |
114
- IColumnState |
115
- IFilteringExpressionsTree |
116
- ISortingExpression |
117
- IGroupingExpression |
118
- IPagingState | string ) {
117
+ public setState ( state : IGridState | string ) {
119
118
if ( typeof state === 'string' ) {
120
119
state = JSON . parse ( state as string , this . parseCallback ) as string ;
121
120
}
122
- this . state = state as IGridState | IColumnState | IFilteringExpressionsTree |
123
- ISortingExpression | IGroupingExpression | IPagingState ;
121
+ this . state = state as IGridState ;
124
122
this . restoreGridState ( this . state ) ;
125
123
}
126
124
@@ -137,25 +135,16 @@ export class IgxGridStateDirective {
137
135
* let state = this.state.getState();
138
136
* ```
139
137
*/
140
- public getState ( serialize = true , feature ?: string | string [ ] ) : IGridState |
141
- IColumnState |
142
- IFilteringExpressionsTree |
143
- ISortingExpression |
144
- IGroupingExpression |
145
- IPagingState | string {
146
- let state : IGridState |
147
- IColumnState |
148
- IFilteringExpressionsTree |
149
- ISortingExpression |
150
- IGroupingExpression |
151
- IPagingState | string ;
138
+ public getState ( serialize = true , feature ?: string | string [ ] ) : IGridState | string {
139
+ let state : IGridState | string ;
152
140
if ( feature ) {
141
+ state = { } ;
153
142
if ( Array . isArray ( feature ) ) {
154
143
feature . forEach ( f => {
155
- state [ f ] = this . getGridFeature ( f ) ;
144
+ state = Object . assign ( state , this . getGridFeature ( f ) ) ;
156
145
} ) ;
157
146
} else {
158
- state [ feature ] = this . getGridFeature ( feature ) ;
147
+ state = this . getGridFeature ( feature ) ;
159
148
}
160
149
} else {
161
150
state = this . getAllGridFeatures ( ) as IGridState ;
@@ -191,7 +180,7 @@ export class IgxGridStateDirective {
191
180
break ;
192
181
}
193
182
case ACTION_ADVANCED_FILTERING : {
194
- state = this . getAdvancedFiltering ( ) ;
183
+ state = this . restoreAdvancedFiltering ( state ) ;
195
184
break ;
196
185
}
197
186
case ACTION_SORTING : {
@@ -206,8 +195,12 @@ export class IgxGridStateDirective {
206
195
this . restorePaging ( state ) ;
207
196
break ;
208
197
}
209
- case ACTION_SELECTION : {
210
- state = this . getSelection ( ) ;
198
+ case ACTION_ROW_SELECTION : {
199
+ state = this . restoreRowSelection ( state ) ;
200
+ break ;
201
+ }
202
+ case ACTION_CELL_SELECTION : {
203
+ state = this . restoreCellSelection ( state ) ;
211
204
break ;
212
205
}
213
206
}
@@ -261,8 +254,12 @@ export class IgxGridStateDirective {
261
254
state = this . getPaging ( ) ;
262
255
break ;
263
256
}
264
- case ACTION_SELECTION : {
265
- state = this . getSelection ( ) ;
257
+ case ACTION_ROW_SELECTION : {
258
+ state = this . getRowSelection ( ) ;
259
+ break ;
260
+ }
261
+ case ACTION_CELL_SELECTION : {
262
+ state = this . getCellSelection ( ) ;
266
263
break ;
267
264
}
268
265
}
@@ -279,6 +276,7 @@ export class IgxGridStateDirective {
279
276
sortable : c . sortable ,
280
277
filterable : c . filterable ,
281
278
editable : c . editable ,
279
+ groupable : c . groupable ,
282
280
movable : c . movable ,
283
281
hidden : c . hidden ,
284
282
dataType : c . dataType ,
@@ -317,9 +315,16 @@ export class IgxGridStateDirective {
317
315
return { groupby : groupingState } ;
318
316
}
319
317
320
- private getSelection ( ) {
318
+ private getRowSelection ( ) {
321
319
const selection = this . grid . selectedRows ( ) ;
322
- return { selection : selection } ;
320
+ return { rowSelection : selection } ;
321
+ }
322
+
323
+ private getCellSelection ( ) {
324
+ const selection = this . grid . selectedCells . map ( cell => {
325
+ return { row : cell . rowIndex , column : cell . columnIndex } ;
326
+ } ) ;
327
+ return { cellSelection : selection } ;
323
328
}
324
329
325
330
/**
@@ -363,7 +368,7 @@ export class IgxGridStateDirective {
363
368
* Restores the grid advanced filtering state, i.e. sets the `advancedFilteringExpressionsTree` property value.
364
369
*/
365
370
private restoreAdvancedFiltering ( state ) {
366
- const advFilterTree = this . createExpressionsTreeFromObject ( state . advancedFiltering ) ;
371
+ const advFilterTree = this . createExpressionsTreeFromObject ( state ) ;
367
372
this . grid . advancedFilteringExpressionsTree = advFilterTree ;
368
373
}
369
374
@@ -410,10 +415,17 @@ export class IgxGridStateDirective {
410
415
}
411
416
}
412
417
413
- private restoreSelection ( state : any [ ] ) {
418
+ private restoreRowSelection ( state : any [ ] ) {
414
419
this . grid . selectRows ( state ) ;
415
420
}
416
421
422
+ private restoreCellSelection ( state : any [ ] ) {
423
+ state . forEach ( cell => {
424
+ const range = { rowStart : cell . row , rowEnd : cell . row , columnStart : cell . column , columnEnd : cell . column } ;
425
+ this . grid . selectRange ( range ) ;
426
+ } ) ;
427
+ }
428
+
417
429
/**
418
430
* This method builds a FilteringExpressionsTree from a provided object.
419
431
*/
@@ -431,7 +443,12 @@ export class IgxGridStateDirective {
431
443
expressionsTree . filteringOperands . push ( subTree ) ;
432
444
} else {
433
445
const expr = item as IFilteringExpression ;
434
- const dataType = this . state [ ACTION_COLUMNS ] . find ( c => c . field === expr . fieldName ) . dataType ;
446
+ let dataType : string ;
447
+ if ( this . grid . columnList . length > 0 ) {
448
+ dataType = this . grid . columnList . find ( c => c . field === expr . fieldName ) . dataType ;
449
+ } else {
450
+ dataType = this . state [ ACTION_COLUMNS ] . find ( c => c . field === expr . fieldName ) . dataType ;
451
+ }
435
452
expr . condition = this . generateFilteringCondition ( dataType , expr . condition . name ) ;
436
453
expr . searchVal = ( dataType === 'date' ) ? new Date ( Date . parse ( expr . searchVal ) ) : expr . searchVal ;
437
454
expressionsTree . filteringOperands . push ( expr ) ;
0 commit comments