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