1
1
import { Component , OnInit } from '@angular/core' ;
2
- import { FilteringExpressionsTree , FilteringLogic , IExpressionTree , IgxQueryBuilderComponent , IgxStringFilteringOperand , IgxQueryBuilderHeaderComponent } from 'igniteui-angular' ;
2
+ import { FilteringExpressionsTree , FilteringLogic , IExpressionTree , IgxBooleanFilteringOperand , IgxDateFilteringOperand , IgxNumberFilteringOperand , IgxQueryBuilderComponent , IgxQueryBuilderHeaderComponent , IgxStringFilteringOperand } from 'igniteui-angular' ;
3
3
4
4
@Component ( {
5
5
selector : 'app-query-builder-sample-1' ,
@@ -8,52 +8,100 @@ import { FilteringExpressionsTree, FilteringLogic, IExpressionTree, IgxQueryBuil
8
8
imports : [ IgxQueryBuilderComponent , IgxQueryBuilderHeaderComponent ]
9
9
} )
10
10
export class QueryBuilderSample1Component implements OnInit {
11
+ public entities : any [ ] ;
12
+ public companiesFields : any [ ] ;
13
+ public ordersFields : any [ ] ;
11
14
public expressionTree : IExpressionTree ;
12
-
13
- public fields : any [ ] = [
14
- { field : 'ID' , dataType : 'string' } ,
15
- { field : 'CompanyName' , dataType : 'string' } ,
16
- { field : 'ContactName' , dataType : 'string' } ,
17
- { field : 'Employees' , dataType : 'number' } ,
18
- { field : 'ContactTitle' , dataType : 'string' } ,
19
- { field : 'DateCreated' , dataType : 'date' } ,
20
- { field : 'TimeCreated' , dataType : 'time' } ,
21
- { field : 'Address' , dataType : 'string' } ,
22
- { field : 'City' , dataType : 'string' } ,
23
- { field : 'Region' , dataType : 'string' } ,
24
- { field : 'PostalCode' , dataType : 'string' } ,
25
- { field : 'Phone' , dataType : 'string' } ,
26
- { field : 'Fax' , dataType : 'string' } ,
27
- { field : 'Contract' , dataType : 'boolean' }
28
- ] ;
29
15
30
16
public ngOnInit ( ) : void {
31
- const tree = new FilteringExpressionsTree ( FilteringLogic . And ) ;
32
- tree . filteringOperands . push ( {
33
- fieldName : 'ID' ,
34
- condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
35
- searchVal : 'a' ,
36
- ignoreCase : true
17
+ this . companiesFields = [
18
+ { field : "ID" , dataType : "string" } ,
19
+ { field : "CompanyName" , dataType : "string" } ,
20
+ { field : "ContactName" , dataType : "string" } ,
21
+ { field : "Employees" , dataType : "number" } ,
22
+ { field : "ContactTitle" , dataType : "string" } ,
23
+ { field : "DateCreated" , dataType : "date" } ,
24
+ { field : "TimeCreated" , dataType : "time" } ,
25
+ { field : "Address" , dataType : "string" } ,
26
+ { field : "City" , dataType : "string" } ,
27
+ { field : "Region" , dataType : "string" } ,
28
+ { field : "PostalCode" , dataType : "string" } ,
29
+ { field : "Phone" , dataType : "string" } ,
30
+ { field : "Fax" , dataType : "string" } ,
31
+ { field : "Contract" , dataType : "boolean" }
32
+ ] ;
33
+
34
+ this . ordersFields = [
35
+ { field : "CompanyID" , dataType : "string" } ,
36
+ { field : "OrderID" , dataType : "number" } ,
37
+ { field : "EmployeeId" , dataType : "number" } ,
38
+ { field : "OrderDate" , dataType : "date" } ,
39
+ { field : "RequiredDate" , dataType : "date" } ,
40
+ { field : "ShippedDate" , dataType : "date" } ,
41
+ { field : "ShipVia" , dataType : "number" } ,
42
+ { field : "Freight" , dataType : "number" } ,
43
+ { field : "ShipName" , dataType : "string" } ,
44
+ { field : "ShipCity" , dataType : "string" } ,
45
+ { field : "ShipPostalCode" , dataType : "string" } ,
46
+ { field : "ShipCountry" , dataType : "string" } ,
47
+ { field : "Region" , dataType : "string" }
48
+ ] ;
49
+
50
+ this . entities = [
51
+ {
52
+ name : "Companies" ,
53
+ fields : this . companiesFields
54
+ } ,
55
+ {
56
+ name : "Orders" ,
57
+ fields : this . ordersFields
58
+ }
59
+ ] ;
60
+
61
+ const innerTree = new FilteringExpressionsTree ( FilteringLogic . And , undefined , 'Companies' , [ 'ID' ] ) ;
62
+ innerTree . filteringOperands . push ( {
63
+ fieldName : 'Employees' ,
64
+ condition : IgxNumberFilteringOperand . instance ( ) . condition ( 'greaterThan' ) ,
65
+ conditionName : 'greaterThan' ,
66
+ searchVal : 100
67
+ } ) ;
68
+ innerTree . filteringOperands . push ( {
69
+ fieldName : 'Contract' ,
70
+ condition : IgxBooleanFilteringOperand . instance ( ) . condition ( 'true' ) ,
71
+ conditionName : 'true'
37
72
} ) ;
38
- const orTree = new FilteringExpressionsTree ( FilteringLogic . Or ) ;
39
- orTree . filteringOperands . push ( {
40
- fieldName : 'ID' ,
41
- condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
42
- searchVal : 'b' ,
43
- ignoreCase : true
73
+
74
+ const subGroup = new FilteringExpressionsTree ( FilteringLogic . Or , undefined , 'Orders' , [ '*' ] ) ;
75
+ subGroup . filteringOperands . push ( {
76
+ fieldName : 'ShipCity' ,
77
+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'endsWith' ) ,
78
+ conditionName : IgxStringFilteringOperand . instance ( ) . condition ( 'endsWith' ) . name ,
79
+ searchVal : 'bar'
80
+ } ) ;
81
+ subGroup . filteringOperands . push ( {
82
+ fieldName : 'OrderDate' ,
83
+ condition : IgxDateFilteringOperand . instance ( ) . condition ( 'today' ) ,
84
+ conditionName : IgxDateFilteringOperand . instance ( ) . condition ( 'today' ) . name
44
85
} ) ;
45
- orTree . filteringOperands . push ( {
46
- fieldName : 'CompanyName' ,
47
- condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
48
- searchVal : 'c' ,
49
- ignoreCase : true
86
+
87
+ const tree = new FilteringExpressionsTree ( FilteringLogic . And , undefined , 'Orders' , [ '*' ] ) ;
88
+ tree . filteringOperands . push ( {
89
+ fieldName : 'CompanyID' ,
90
+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'in' ) ,
91
+ conditionName : 'in' ,
92
+ searchTree : innerTree
93
+ } ) ;
94
+ tree . filteringOperands . push ( {
95
+ fieldName : 'OrderDate' ,
96
+ condition : IgxDateFilteringOperand . instance ( ) . condition ( 'before' ) ,
97
+ conditionName : 'before' ,
98
+ searchVal : new Date ( '2024-01-01T00:00:00.000Z' )
50
99
} ) ;
51
- tree . filteringOperands . push ( orTree ) ;
100
+ tree . filteringOperands . push ( subGroup ) ;
52
101
tree . filteringOperands . push ( {
53
- fieldName : 'CompanyName' ,
54
- condition : IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ,
55
- searchVal : 'd' ,
56
- ignoreCase : true
102
+ fieldName : 'ShippedDate' ,
103
+ condition : IgxDateFilteringOperand . instance ( ) . condition ( 'null' ) ,
104
+ conditionName : 'null'
57
105
} ) ;
58
106
59
107
this . expressionTree = tree ;
@@ -62,4 +110,4 @@ export class QueryBuilderSample1Component implements OnInit {
62
110
public printExpressionTree ( tree : IExpressionTree ) {
63
111
return tree ? JSON . stringify ( tree , null , 2 ) : 'Please add an expression!' ;
64
112
}
65
- }
113
+ }
0 commit comments