11import {
22 Component ,
3- EventEmitter ,
4- OnDestroy ,
5- OnInit ,
6- Output ,
3+ Input ,
74 ViewChild } from '@angular/core' ;
85import {
96 DefaultSortingStrategy ,
107 IgxGridComponent ,
118 SortingDirection
129} from 'igniteui-angular' ;
1310import { Contract , REGIONS } from '../shared/financialData' ;
14- 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+ ] ;
1531
1632@Component ( {
1733 selector : 'app-finjs-grid' ,
1834 styleUrls : [ './grid-finjs.component.scss' ] ,
1935 templateUrl : './grid-finjs.component.html'
2036} )
21- export class GridFinJSComponent implements OnInit , OnDestroy {
37+ export class GridFinJSComponent {
2238 @ViewChild ( 'grid1' , { static : true } ) public grid : IgxGridComponent ;
2339
24- @Output ( ) public selectedDataChanged = new EventEmitter < any > ( ) ;
25- @Output ( ) public keyDown = new EventEmitter < any > ( ) ;
26- @Output ( ) public chartColumnKeyDown = new EventEmitter < any > ( ) ;
40+ @Input ( )
41+ public data : any ;
2742
28- public data = [ ] ;
2943 public selectionMode = 'multiple' ;
3044 public contracts = Contract ;
3145 public regions = REGIONS ;
3246 public columnFormat = { digitsInfo : '1.3-3' } ;
3347 public showToolbar = true ;
34- public volume = 1000 ;
35- public frequency = 500 ;
36- private subscription$ ;
37-
38- constructor ( public finService : LocalService ) {
39- this . finService . getFinancialData ( this . volume ) ;
40- this . subscription$ = this . finService . records . subscribe ( x => {
41- this . data = x ;
42- } ) ;
43- }
44-
45- public ngOnInit ( ) {
46- this . grid . groupingExpressions = [ {
47- dir : SortingDirection . Desc ,
48- fieldName : 'Category' ,
49- ignoreCase : false ,
50- strategy : DefaultSortingStrategy . instance ( )
51- } ,
52- {
53- dir : SortingDirection . Desc ,
54- fieldName : 'Type' ,
55- ignoreCase : false ,
56- strategy : DefaultSortingStrategy . instance ( )
57- } ,
58- {
59- dir : SortingDirection . Desc ,
60- fieldName : 'Settlement' ,
61- ignoreCase : false ,
62- strategy : DefaultSortingStrategy . instance ( )
63- }
64- ] ;
65- }
48+ public groupingExpressions = GROUPING_EXPRESSIONS ;
6649
67- public ngOnDestroy ( ) {
68- if ( this . subscription$ ) {
69- this . subscription$ . unsubscribe ( ) ;
70- }
71- }
72-
73- /** Event Handlers */
74-
75- public onChange ( ) {
76- if ( this . grid . groupingExpressions . length > 0 ) {
77- this . grid . groupingExpressions = [ ] ;
78- } else {
79- this . grid . groupingExpressions = [ {
80- dir : SortingDirection . Desc ,
81- fieldName : 'Category' ,
82- ignoreCase : false ,
83- strategy : DefaultSortingStrategy . instance ( )
84- } ,
85- {
86- dir : SortingDirection . Desc ,
87- fieldName : 'Type' ,
88- ignoreCase : false ,
89- strategy : DefaultSortingStrategy . instance ( )
90- } ,
91- {
92- dir : SortingDirection . Desc ,
93- fieldName : 'Contract' ,
94- ignoreCase : false ,
95- strategy : DefaultSortingStrategy . instance ( )
96- }
97- ] ;
98- }
99- }
50+ constructor ( ) { }
10051
101- public toggleGrouping ( ) {
102- if ( this . grid . groupingExpressions . length > 0 ) {
103- this . grid . groupingExpressions = [ ] ;
104- } else {
105- this . grid . groupingExpressions = [ {
106- dir : SortingDirection . Desc ,
107- fieldName : 'Category' ,
108- ignoreCase : false ,
109- strategy : DefaultSortingStrategy . instance ( )
110- } ,
111- {
112- dir : SortingDirection . Desc ,
113- fieldName : 'Type' ,
114- ignoreCase : false ,
115- strategy : DefaultSortingStrategy . instance ( )
116- } ,
117- {
118- dir : SortingDirection . Desc ,
119- fieldName : 'Contract' ,
120- ignoreCase : false ,
121- strategy : DefaultSortingStrategy . instance ( )
122- }
123- ] ;
124- }
52+ public toggleGrouping ( newValue : boolean ) {
53+ this . groupingExpressions = newValue ? GROUPING_EXPRESSIONS : [ ] ;
12554 }
12655
12756 /** Grid CellStyles and CellClasses */
@@ -132,7 +61,6 @@ export class GridFinJSComponent implements OnInit, OnDestroy {
13261 private strongPositive = ( rowData : any ) : boolean => rowData [ 'Change(%)' ] >= 1 ;
13362 private strongNegative = ( rowData : any ) : boolean => rowData [ 'Change(%)' ] <= - 1 ;
13463
135- /* eslint-disable @typescript-eslint/member-ordering */
13664 public trends = {
13765 changeNeg : this . changeNegative ,
13866 changePos : this . changePositive ,
@@ -148,9 +76,4 @@ export class GridFinJSComponent implements OnInit, OnDestroy {
14876 strongNegative2 : this . strongNegative ,
14977 strongPositive2 : this . strongPositive
15078 } ;
151- /* eslint-enable @typescript-eslint/member-ordering */
152-
153- public get grouped ( ) : boolean {
154- return this . grid . groupingExpressions . length > 0 ;
155- }
15679}
0 commit comments