1
1
import { Component , OnInit } from '@angular/core' ;
2
+ import { Router } from '@angular/router' ;
2
3
3
- import { AngularGridInstance , Column , GridOption , FieldType , GraphqlService , GraphqlResult } from 'angular-slickgrid' ;
4
+ import { AngularGridInstance , Column , GridOption , GraphqlService , GraphqlResult , Filters , Formatter , Formatters , OnEventArgs , FieldType } from 'angular-slickgrid' ;
4
5
5
6
import { ProductDataService } from 'src/app/core/services/product-data.service' ;
6
7
8
+
7
9
const GRAPHQL_QUERY_DATASET_NAME = 'products' ;
8
10
11
+
9
12
@Component ( {
10
13
templateUrl : './product-list.component.html' ,
11
14
styleUrls : [ './product-list.component.css' ]
@@ -16,15 +19,28 @@ export class ProductListComponent implements OnInit {
16
19
gridOptions : GridOption ;
17
20
dataset = [ ] ;
18
21
19
- constructor ( private dataService : ProductDataService ) {
22
+ constructor ( private dataService : ProductDataService , private router : Router ) {
20
23
}
21
24
22
25
ngOnInit ( ) : void {
23
26
this . columnDefinitions = [
24
- { id : 'id' , field : 'id' , name : 'Id' , filterable : true , sortable : true , type : FieldType . number } ,
25
- { id : 'name' , field : 'name' , name : 'Name' , filterable : true , sortable : true , type : FieldType . string } ,
26
- { id : 'unitPrice' , field : 'unitPrice' , name : 'Unit Price' , filterable : true , sortable : true , type : FieldType . number } ,
27
- { id : 'category.id' , field : 'category.id' , name : 'Category' , filterable : true , sortable : true , type : FieldType . string } ,
27
+ {
28
+ id : 'edit' ,
29
+ field : 'id' ,
30
+ excludeFromColumnPicker : true ,
31
+ excludeFromGridMenu : true ,
32
+ excludeFromHeaderMenu : true ,
33
+ formatter : Formatters . editIcon ,
34
+ minWidth : 30 ,
35
+ maxWidth : 30 ,
36
+ onCellClick : ( e : Event , args : OnEventArgs ) => {
37
+ this . router . navigate ( [ '/product/product-detail/' + args . dataContext . id ] ) ;
38
+ }
39
+ } ,
40
+ { id : 'id' , field : 'id' , name : 'Id' , filterable : true , sortable : true , maxWidth : 200 , type : FieldType . number , filter : { model : Filters . inputNumber } } ,
41
+ { id : 'name' , field : 'name' , name : 'Name' , filterable : true , sortable : true } ,
42
+ { id : 'unitPrice' , field : 'unitPrice' , name : 'Unit Price' , filterable : true , sortable : true , maxWidth : 200 , filter : { model : Filters . inputNumber } } ,
43
+ { id : 'category' , field : 'category.name' , name : 'Category' , filterable : true , sortable : true , formatter : Formatters . complexObject } ,
28
44
] ;
29
45
30
46
this . gridOptions = {
@@ -36,7 +52,7 @@ export class ProductListComponent implements OnInit {
36
52
isWithCursor : false ,
37
53
keepArgumentFieldDoubleQuotes : true
38
54
} ,
39
- process : ( query ) => this . getProducts ( query ) ,
55
+ process : ( query ) => this . getProducts ( ) ,
40
56
}
41
57
} ; ;
42
58
}
@@ -45,8 +61,16 @@ export class ProductListComponent implements OnInit {
45
61
this . angularGrid = angularGrid ;
46
62
}
47
63
48
- getProducts ( query : string ) : Promise < GraphqlResult > {
49
- return new Promise ( ( resolve , reject ) => {
64
+ getProducts ( ) : Promise < GraphqlResult > {
65
+
66
+ if ( this . angularGrid ) {
67
+ var a = this . angularGrid . backendService . getCurrentFilters ( ) ;
68
+ var b = this . angularGrid . backendService . getCurrentSorters ( ) ;
69
+ var c = this . angularGrid . backendService . getCurrentPagination ( ) ;
70
+ var d = 0 ;
71
+ }
72
+
73
+ return new Promise ( ( resolve ) => {
50
74
this . dataService . getProductsByName ( "" )
51
75
. toPromise ( )
52
76
. then (
0 commit comments