1
1
import {
2
- AfterViewInit ,
3
2
Component ,
4
- EventEmitter ,
5
- OnDestroy ,
6
- OnInit ,
7
- Output ,
3
+ Input ,
8
4
ViewChild } from '@angular/core' ;
9
5
import {
10
6
DefaultSortingStrategy ,
11
- GridSelectionMode ,
12
7
IgxGridComponent ,
13
8
SortingDirection
14
9
} from 'igniteui-angular' ;
15
10
import { Contract , REGIONS } from '../shared/financialData' ;
16
- import { LocalService } from '../shared/local.service' ;
11
+
12
+ const GROUPING_EXPRESSIONS = [ {
13
+ dir : SortingDirection . Desc ,
14
+ fieldName : 'Category' ,
15
+ ignoreCase : false ,
16
+ strategy : DefaultSortingStrategy . instance ( )
17
+ } ,
18
+ {
19
+ dir : SortingDirection . Desc ,
20
+ fieldName : 'Type' ,
21
+ ignoreCase : false ,
22
+ strategy : DefaultSortingStrategy . instance ( )
23
+ } ,
24
+ {
25
+ dir : SortingDirection . Desc ,
26
+ fieldName : 'Contract' ,
27
+ ignoreCase : false ,
28
+ strategy : DefaultSortingStrategy . instance ( )
29
+ }
30
+ ] ;
17
31
18
32
@Component ( {
19
33
selector : 'app-finjs-grid' ,
20
34
styleUrls : [ './grid-finjs.component.scss' ] ,
21
35
templateUrl : './grid-finjs.component.html'
22
36
} )
23
- export class GridFinJSComponent implements OnInit , AfterViewInit , OnDestroy {
37
+ export class GridFinJSComponent {
24
38
@ViewChild ( 'grid1' , { static : true } ) public grid : IgxGridComponent ;
25
39
26
- @Output ( ) public selectedDataChanged = new EventEmitter < any > ( ) ;
27
- @Output ( ) public keyDown = new EventEmitter < any > ( ) ;
28
- @Output ( ) public chartColumnKeyDown = new EventEmitter < any > ( ) ;
40
+ @Input ( )
41
+ public data : any ;
29
42
30
- public data = [ ] ;
31
- public multiCellSelection : { data : any [ ] } = { data : [ ] } ;
32
- public selectionMode : GridSelectionMode = 'multiple' ;
43
+ public selectionMode = 'multiple' ;
33
44
public contracts = Contract ;
34
45
public regions = REGIONS ;
46
+ public columnFormat = { digitsInfo : '1.3-3' } ;
35
47
public showToolbar = true ;
36
- public volume = 1000 ;
37
- public frequency = 500 ;
38
- private subscription$ ;
39
-
40
- constructor ( public finService : LocalService ) {
41
- this . finService . getFinancialData ( this . volume ) ;
42
- this . subscription$ = this . finService . records . subscribe ( x => {
43
- this . data = x ;
44
- } ) ;
45
- }
48
+ public groupingExpressions = GROUPING_EXPRESSIONS ;
46
49
47
- public ngOnInit ( ) {
48
- this . grid . groupingExpressions = [ {
49
- dir : SortingDirection . Desc ,
50
- fieldName : 'Category' ,
51
- ignoreCase : false ,
52
- strategy : DefaultSortingStrategy . instance ( )
53
- } ,
54
- {
55
- dir : SortingDirection . Desc ,
56
- fieldName : 'Type' ,
57
- ignoreCase : false ,
58
- strategy : DefaultSortingStrategy . instance ( )
59
- } ,
60
- {
61
- dir : SortingDirection . Desc ,
62
- fieldName : 'Settlement' ,
63
- ignoreCase : false ,
64
- strategy : DefaultSortingStrategy . instance ( )
65
- }
66
- ] ;
67
- }
50
+ constructor ( ) { }
68
51
69
- public ngAfterViewInit ( ) {
70
- this . grid . hideGroupedColumns = true ;
71
- this . grid . reflow ( ) ;
72
- }
73
-
74
- public ngOnDestroy ( ) {
75
- if ( this . subscription$ ) {
76
- this . subscription$ . unsubscribe ( ) ;
77
- }
78
- }
79
-
80
- /** Event Handlers */
81
-
82
- public onChange ( ) {
83
- if ( this . grid . groupingExpressions . length > 0 ) {
84
- this . grid . groupingExpressions = [ ] ;
85
- } else {
86
- this . grid . groupingExpressions = [ {
87
- dir : SortingDirection . Desc ,
88
- fieldName : 'Category' ,
89
- ignoreCase : false ,
90
- strategy : DefaultSortingStrategy . instance ( )
91
- } ,
92
- {
93
- dir : SortingDirection . Desc ,
94
- fieldName : 'Type' ,
95
- ignoreCase : false ,
96
- strategy : DefaultSortingStrategy . instance ( )
97
- } ,
98
- {
99
- dir : SortingDirection . Desc ,
100
- fieldName : 'Contract' ,
101
- ignoreCase : false ,
102
- strategy : DefaultSortingStrategy . instance ( )
103
- }
104
- ] ;
105
- }
106
- }
107
-
108
- public toggleGrouping ( ) {
109
- if ( this . grid . groupingExpressions . length > 0 ) {
110
- this . grid . groupingExpressions = [ ] ;
111
- } else {
112
- this . grid . groupingExpressions = [ {
113
- dir : SortingDirection . Desc ,
114
- fieldName : 'Category' ,
115
- ignoreCase : false ,
116
- strategy : DefaultSortingStrategy . instance ( )
117
- } ,
118
- {
119
- dir : SortingDirection . Desc ,
120
- fieldName : 'Type' ,
121
- ignoreCase : false ,
122
- strategy : DefaultSortingStrategy . instance ( )
123
- } ,
124
- {
125
- dir : SortingDirection . Desc ,
126
- fieldName : 'Contract' ,
127
- ignoreCase : false ,
128
- strategy : DefaultSortingStrategy . instance ( )
129
- }
130
- ] ;
131
- }
132
- }
133
-
134
- /** Grid Formatters */
135
- public formatNumber ( value : number ) {
136
- return value . toFixed ( 2 ) ;
137
- }
138
-
139
- public percentage ( value : number ) {
140
- return value . toFixed ( 2 ) + '%' ;
141
- }
142
-
143
- public formatCurrency ( value : number ) {
144
- return '$' + value . toFixed ( 3 ) ;
52
+ public toggleGrouping ( newValue : boolean ) {
53
+ this . groupingExpressions = newValue ? GROUPING_EXPRESSIONS : [ ] ;
145
54
}
146
55
147
56
/** Grid CellStyles and CellClasses */
@@ -152,7 +61,7 @@ export class GridFinJSComponent implements OnInit, AfterViewInit, OnDestroy {
152
61
private strongPositive = ( rowData : any ) : boolean => rowData [ 'Change(%)' ] >= 1 ;
153
62
private strongNegative = ( rowData : any ) : boolean => rowData [ 'Change(%)' ] <= - 1 ;
154
63
155
- /* eslint-disable @typescript-eslint/member-ordering */
64
+ // eslint-disable-next-line @typescript-eslint/member-ordering
156
65
public trends = {
157
66
changeNeg : this . changeNegative ,
158
67
changePos : this . changePositive ,
@@ -161,16 +70,11 @@ export class GridFinJSComponent implements OnInit, AfterViewInit, OnDestroy {
161
70
strongNegative : this . strongNegative ,
162
71
strongPositive : this . strongPositive
163
72
} ;
164
-
73
+ // eslint-disable-next-line @typescript-eslint/member-ordering
165
74
public trendsChange = {
166
75
changeNeg2 : this . changeNegative ,
167
76
changePos2 : this . changePositive ,
168
77
strongNegative2 : this . strongNegative ,
169
78
strongPositive2 : this . strongPositive
170
79
} ;
171
- /* eslint-enable @typescript-eslint/member-ordering */
172
-
173
- public get grouped ( ) : boolean {
174
- return this . grid . groupingExpressions . length > 0 ;
175
- }
176
80
}
0 commit comments