-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathquery-builder-request-sample.component.ts
More file actions
76 lines (65 loc) · 2.9 KB
/
query-builder-request-sample.component.ts
File metadata and controls
76 lines (65 loc) · 2.9 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
import { HttpClient } from '@angular/common/http';
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { FilteringExpressionsTree, FilteringLogic, IExpressionTree, IgxColumnComponent, IgxGridComponent, IgxQueryBuilderComponent } from 'igniteui-angular';
const API_ENDPOINT = 'https://data-northwind.indigo.design';
@Component({
selector: 'query-builder-request-sample',
styleUrls: ['./query-builder-request-sample.component.scss'],
templateUrl: 'query-builder-request-sample.component.html',
imports: [IgxQueryBuilderComponent, IgxGridComponent, IgxColumnComponent]
})
export class QueryBuilderRequestSampleComponent implements OnInit {
@ViewChild('grid', { static: true })
public grid: IgxGridComponent;
public entities: any[];
public customersFields: any[];
public ordersFields: any[];
public expressionTree: IExpressionTree;
public data: any[] = [];
constructor(private http: HttpClient, private cdr: ChangeDetectorRef) {}
public ngOnInit(): void {
this.customersFields = [
{ field: "customerId", dataType: "string" },
{ field: "companyName", dataType: "string" },
{ field: "contactName", dataType: "string" },
{ field: "contactTitle", dataType: "string" }
];
this.ordersFields = [
{ field: "orderId", dataType: "number" },
{ field: "customerId", dataType: "string" },
{ field: "employeeId", dataType: "number" },
{ field: "shipperId", dataType: "number" },
{ field: "orderDate", dataType: "date" },
{ field: "requiredDate", dataType: "date" },
{ field: "shipVia", dataType: "number" },
{ field: "freight", dataType: "number" },
{ field: "shipName", dataType: "string" },
{ field: "completed", dataType: "boolean" }
];
this.entities = [
{
name: "Customers",
fields: this.customersFields
},
{
name: "Orders",
fields: this.ordersFields
}
];
const tree = new FilteringExpressionsTree(FilteringLogic.And, undefined, 'Orders', ['orderId', 'customerId', 'employeeId', 'shipperId', 'orderDate', 'requiredDate', 'shipVia', 'freight', 'shipName', 'completed']);
this.expressionTree = tree;
this.onChange();
}
public onChange() {
this.grid.isLoading = true;
this.http.post(`${API_ENDPOINT}/QueryBuilder/ExecuteQuery`, this.expressionTree).subscribe(data =>{
this.data = Object.values(data)[0];
this.grid.isLoading = false;
});
this.cdr.detectChanges();
this.calculateColsInView();
}
private calculateColsInView() {
this.grid.columns.forEach(column => column.hidden = !this.expressionTree.returnFields.includes(column.field));
}
}