1
1
import { Component , OnInit , ViewChild , AfterViewInit } from '@angular/core' ;
2
2
import { IgxGridComponent , FilteringExpressionsTree , FilteringLogic ,
3
- IPagingState , IGroupingExpression , ISortingExpression } from 'igniteui-angular' ;
3
+ IPagingState , IGroupingExpression , ISortingExpression , IgxNumberSummaryOperand , IgxSummaryResult ,
4
+ IgxGridStateDirective , IGridState , IColumnState } from 'igniteui-angular' ;
4
5
import { employeesData } from './localData' ;
5
6
import { take } from 'rxjs/operators' ;
6
7
import { NavigationStart , Router } from '@angular/router' ;
7
- import { IgxGridStateDirective , IGridState } from 'projects/igniteui-angular/src/lib/grids/state.directive' ;
8
-
9
- interface IColumnState {
10
- field : string ;
11
- header : string ;
12
- width ?: string ;
13
- groupable ?: boolean ;
14
- dataType ?: string ;
15
- pinned ?: boolean ;
16
- sortable ?: boolean ;
17
- filterable ?: boolean ;
18
- movable ?: true ;
19
- hidden ?: boolean ;
8
+
9
+ class MySummary extends IgxNumberSummaryOperand {
10
+
11
+ constructor ( ) {
12
+ super ( ) ;
13
+ }
14
+
15
+ operate ( data ?: any [ ] ) : IgxSummaryResult [ ] {
16
+ const result = super . operate ( data ) ;
17
+ result . push ( {
18
+ key : 'test' ,
19
+ label : 'Test' ,
20
+ summaryResult : data . filter ( rec => rec > 10 && rec < 30 ) . length
21
+ } ) ;
22
+ return result ;
23
+ }
20
24
}
21
25
22
26
@Component ( {
@@ -40,20 +44,20 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
40
44
advancedFiltering : true ,
41
45
paging : true ,
42
46
sorting : true ,
43
- groupby : true ,
47
+ groupBy : true ,
44
48
columns : true
45
49
} ;
46
50
47
51
@ViewChild ( IgxGridStateDirective , { static : true } ) public state : IgxGridStateDirective ;
48
52
@ViewChild ( IgxGridComponent , { static : true } ) public grid : IgxGridComponent ;
49
53
50
- public initialColumns : IColumnState [ ] = [
54
+ public initialColumns : any [ ] = [
51
55
// tslint:disable:max-line-length
52
- { field : 'FirstName' , header : 'First Name' , width : '150px' , dataType : 'string' , pinned : true , movable : true , sortable : true , filterable : true } ,
53
- { field : 'LastName' , header : 'Last Name' , width : '150px' , dataType : 'string' , pinned : true , movable : true , sortable : true , filterable : true } ,
54
- { field : 'Country' , header : 'Country' , width : '140px' , dataType : 'string' , groupable : true , movable : true , sortable : true , filterable : true } ,
55
- { field : 'Age' , header : 'Age' , width : '110px' , dataType : 'number' , movable : true , sortable : true , filterable : true } ,
56
- { field : 'RegistererDate' , header : 'Registerer Date' , width : '180px' , dataType : 'date' , movable : true , sortable : true , filterable : true } ,
56
+ { field : 'FirstName' , header : 'First Name' , width : '150px' , dataType : 'string' , pinned : true , movable : true , sortable : true , filterable : true , summaries : MySummary } ,
57
+ { field : 'LastName' , header : 'Last Name' , width : '150px' , dataType : 'string' , pinned : true , movable : true , sortable : true , filterable : true } ,
58
+ { field : 'Country' , header : 'Country' , width : '140px' , dataType : 'string' , groupable : true , movable : true , sortable : true , filterable : true , resizable : true } ,
59
+ { field : 'Age' , header : 'Age' , width : '110px' , dataType : 'number' , movable : true , sortable : true , filterable : true , hasSummary : true , summaries : MySummary , resizable : true } ,
60
+ { field : 'RegistererDate' , header : 'Registerer Date' , width : '180px' , dataType : 'date' , movable : true , sortable : true , filterable : true , resizable : true } ,
57
61
{ field : 'IsActive' , header : 'Is Active' , width : '140px' , dataType : 'boolean' , groupable : true , movable : true , sortable : true , filterable : true }
58
62
// tslint:enable:max-line-length
59
63
] ;
@@ -121,13 +125,13 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
121
125
122
126
public getColumnsState ( ) : any {
123
127
let state = window . localStorage . getItem ( this . stateKey ) ;
124
- state = JSON . parse ( state ) [ ' columns' ] ;
128
+ state = state ? JSON . parse ( state ) . columns : null ;
125
129
return state ;
126
130
}
127
131
128
132
public restoreFiltering ( ) {
129
133
const state = window . localStorage . getItem ( this . stateKey ) ;
130
- const filteringState : FilteringExpressionsTree = JSON . parse ( state ) . filtering ;
134
+ const filteringState : FilteringExpressionsTree = state ? JSON . parse ( state ) . filtering : null ;
131
135
if ( filteringState ) {
132
136
const gridFilteringState : IGridState = { filtering : filteringState } ;
133
137
this . state . setState ( gridFilteringState ) ;
@@ -136,7 +140,7 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
136
140
137
141
public restoreAdvancedFiltering ( ) {
138
142
const state = window . localStorage . getItem ( this . stateKey ) ;
139
- const advFilteringState : FilteringExpressionsTree = JSON . parse ( state ) . advancedFiltering ;
143
+ const advFilteringState : FilteringExpressionsTree = state ? JSON . parse ( state ) . advancedFiltering : null ;
140
144
if ( advFilteringState ) {
141
145
const gridAdvancedFilteringState : IGridState = { advancedFiltering : advFilteringState } ;
142
146
this . state . setState ( gridAdvancedFilteringState ) ;
@@ -145,34 +149,34 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
145
149
146
150
public restoreSorting ( ) {
147
151
const state = window . localStorage . getItem ( this . stateKey ) ;
148
- const sortingState : ISortingExpression [ ] = JSON . parse ( state ) . sorting ;
149
- if ( state ) {
152
+ const sortingState : ISortingExpression [ ] = state ? JSON . parse ( state ) . sorting : null ;
153
+ if ( sortingState ) {
150
154
const gridSortingState : IGridState = { sorting : sortingState } ;
151
155
this . state . setState ( gridSortingState ) ;
152
156
}
153
157
}
154
158
155
159
public restoreGroupby ( ) {
156
160
const state = window . localStorage . getItem ( this . stateKey ) ;
157
- const groupByState : IGroupingExpression [ ] = JSON . parse ( state ) . groupby ;
158
- if ( state ) {
161
+ const groupByState : IGroupingExpression [ ] = state ? JSON . parse ( state ) . groupBy : null ;
162
+ if ( groupByState ) {
159
163
const gridGroupiByState : IGridState = { groupBy : groupByState } ;
160
164
this . state . setState ( gridGroupiByState ) ;
161
165
}
162
166
}
163
167
164
168
public restoreRowSelection ( ) {
165
169
const state = window . localStorage . getItem ( this . stateKey ) ;
166
- const rowSelectionState = JSON . parse ( state ) . rowSelection ;
167
- if ( state ) {
170
+ const rowSelectionState = state ? JSON . parse ( state ) . rowSelection : null ;
171
+ if ( rowSelectionState ) {
168
172
const gridRowSelectionState : IGridState = { rowSelection : rowSelectionState } ;
169
173
this . state . setState ( gridRowSelectionState ) ;
170
174
}
171
175
}
172
176
173
177
public restoreCellSelection ( ) {
174
178
const state = window . localStorage . getItem ( this . stateKey ) ;
175
- const cellSelectionState = JSON . parse ( state ) . cellSelection ;
179
+ const cellSelectionState = state ? JSON . parse ( state ) . cellSelection : null ;
176
180
if ( state ) {
177
181
const gridCellSelectionState : IGridState = { cellSelection : cellSelectionState } ;
178
182
this . state . setState ( gridCellSelectionState ) ;
@@ -181,7 +185,7 @@ export class GridSaveStateComponent implements OnInit, AfterViewInit {
181
185
182
186
public restorePaging ( ) {
183
187
const state = window . localStorage . getItem ( this . stateKey ) ;
184
- const pagingState : IPagingState = JSON . parse ( state ) . paging ;
188
+ const pagingState : IPagingState = state ? JSON . parse ( state ) . paging : null ;
185
189
if ( state ) {
186
190
const gridPagingState : IGridState = { paging : pagingState } ;
187
191
this . state . setState ( gridPagingState ) ;
0 commit comments