1+ import { HttpClient } from '@angular/common/http' ;
2+ import { ChangeDetectorRef , Component , OnInit , ViewChild } from '@angular/core' ;
3+ import { FilteringExpressionsTree , FilteringLogic , IExpressionTree , IgxColumnComponent , IgxGridComponent , IgxQueryBuilderComponent } from 'igniteui-angular' ;
4+
5+ const API_ENDPOINT = 'https://data-northwind.indigo.design' ;
6+
7+ @Component ( {
8+ selector : 'query-builder-request-sample' ,
9+ styleUrls : [ './query-builder-request-sample.component.scss' ] ,
10+ templateUrl : 'query-builder-request-sample.component.html' ,
11+ imports : [ IgxQueryBuilderComponent , IgxGridComponent , IgxColumnComponent ]
12+ } )
13+ export class QueryBuilderRequestSampleComponent implements OnInit {
14+ @ViewChild ( 'grid' , { static : true } )
15+ public grid : IgxGridComponent ;
16+
17+ public entities : any [ ] ;
18+ public customersFields : any [ ] ;
19+ public ordersFields : any [ ] ;
20+ public expressionTree : IExpressionTree ;
21+ public data : any [ ] = [ ] ;
22+
23+ constructor ( private http : HttpClient , private cdr : ChangeDetectorRef ) { }
24+
25+ public ngOnInit ( ) : void {
26+ this . customersFields = [
27+ { field : "customerId" , dataType : "string" } ,
28+ { field : "companyName" , dataType : "string" } ,
29+ { field : "contactName" , dataType : "string" } ,
30+ { field : "contactTitle" , dataType : "string" }
31+ ] ;
32+
33+ this . ordersFields = [
34+ { field : "orderId" , dataType : "number" } ,
35+ { field : "customerId" , dataType : "string" } ,
36+ { field : "employeeId" , dataType : "number" } ,
37+ { field : "shipperId" , dataType : "number" } ,
38+ { field : "orderDate" , dataType : "date" } ,
39+ { field : "requiredDate" , dataType : "date" } ,
40+ { field : "shipVia" , dataType : "number" } ,
41+ { field : "freight" , dataType : "number" } ,
42+ { field : "shipName" , dataType : "string" } ,
43+ { field : "completed" , dataType : "boolean" }
44+ ] ;
45+
46+ this . entities = [
47+ {
48+ name : "Customers" ,
49+ fields : this . customersFields
50+ } ,
51+ {
52+ name : "Orders" ,
53+ fields : this . ordersFields
54+ }
55+ ] ;
56+
57+ const tree = new FilteringExpressionsTree ( FilteringLogic . And , undefined , 'Orders' , [ 'orderId' , 'customerId' , 'employeeId' , 'shipperId' , 'orderDate' , 'requiredDate' , 'shipVia' , 'freight' , 'shipName' , 'completed' ] ) ;
58+ this . expressionTree = tree ;
59+
60+ this . onChange ( ) ;
61+ }
62+
63+ public onChange ( ) {
64+ this . grid . isLoading = true ;
65+ this . http . post ( `${ API_ENDPOINT } /QueryBuilder/ExecuteQuery` , this . expressionTree ) . subscribe ( data => {
66+ this . data = Object . values ( data ) [ 0 ] ;
67+ this . grid . isLoading = false ;
68+ } ) ;
69+ this . cdr . detectChanges ( ) ;
70+ this . calculateColsInView ( ) ;
71+ }
72+
73+ private calculateColsInView ( ) {
74+ this . grid . columns . forEach ( column => column . hidden = ! this . expressionTree . returnFields . includes ( column . field ) ) ;
75+ }
76+ }
0 commit comments