How to get started easily with Syncfusion Angular 11 Query builder?
A quick start project that helps you to create an Angular 11 Query Builder with a minimal code configurations.
The following section explains you how to create a simple angular 11 Query Builder component.
Prerequisites
Before start, we need following items to create Angular Query Builder in Angular 11 application
- Node.js
- Angular 11
- Angular CLI
- Typescript 4+
- Visual Studio Code for Editor
Dependencies
The angular 11 Query Builder is created from the Syncfusion ej2-angular-querybuilder package from npmjs, which are distributed in npm as @syncfusion scoped packages.
Creating Angular Project
- Install Angular cli 11 using following command.
npm install -g @angular/cli@11.2.3
If you would like to follow and run the application in Angular 6 or Angular 5 or Angular 4, you need to replace the CLI command version number with the corresponding angular version number.
npm install -g @angular/cli@<CLI VERSION>
- Create a new Angular 11 project using angular cli and navigate to that folder.
ng new angular11-app cd angular11-app
Adding Angular Query Builder
- After running the Angular 11 application successfully, configure the Angular Query Builder in this application. Install Angular Query Builder and EJ2 package using following command.
npm install @syncfusion/ej2-angular-querybuilder --save
The --save command will instruct the NPM to include a Query Builder package inside the dependencies section of the package.json.
- Import Query Builder from installed package.
- Import and inject the other required modules within the providers section of app.module.ts.
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { QueryBuilderModule } from '@syncfusion/ej2-angular-querybuilder'; import { AppComponent } from './app.component'; import { enableRipple } from '@syncfusion/ej2-base'; enableRipple(true); @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, QueryBuilderModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule {}
- Add the given below angular query builder’s styles in styles.css.
@import "../node_modules/@syncfusion/ej2-base/styles/material.css"; @import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css"; @import "../node_modules/@syncfusion/ej2-buttons/styles/material.css"; @import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css"; @import "../node_modules/@syncfusion/ej2-inputs/styles/material.css"; @import "../node_modules/@syncfusion/ej2-calendars/styles/material.css"; @import "../node_modules/@syncfusion/ej2-popups/styles/material.css"; @import "../node_modules/@syncfusion/ej2-querybuilder/styles/material.css";
- Add the angular Query Builder component in app.component.ts.
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: `<ejs-querybuilder width="70%"> <e-columns> <e-column field="EmployeeID" label="Employee ID" type="number"></e-column> <e-column field="FirstName" label="First Name" type="string"></e-column> <e-column field="TitleOfCourtesy" label="Title Of Courtesy" type="boolean" [values]="values"></e-column> <e-column field="Title" label="Title" type="string"></e-column> <e-column field="HireDate" label="Hire Date" type="date" format="dd/MM/yyyy"></e-column> <e-column field="Country" label="Country" type="string"></e-column> <e-column field="City" label="City" type="string"></e-column> </e-columns> </ejs-querybuilder>` }) export class AppComponent { public values: string[] = ['Mr.', 'Mrs.']; }
- Now serve the application using following command.
ng serve
Once the files are compiled successfully, it will serve the site at localhost:4200
Screenshot:
Rendering with Rule
You can render the Query Builder component with rule, using the rule property.
[app.component.ts]
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: `<ejs-querybuilder width="70%" [rule] = "importRules"> <e-columns> <e-column field="EmployeeID" label="Employee ID" type="number"></e-column> <e-column field="FirstName" label="First Name" type="string"></e-column> <e-column field="TitleOfCourtesy" label="Title Of Courtesy" type="boolean" [values]="values"></e-column> <e-column field="Title" label="Title" type="string"></e-column> <e-column field="HireDate" label="Hire Date" type="date" format="dd/MM/yyyy"></e-column> <e-column field="Country" label="Country" type="string"></e-column> <e-column field="City" label="City" type="string"></e-column> </e-columns> </ejs-querybuilder >` }) export class AppComponent implements OnInit { public importRules: RuleModel; public values: string[] = ['Mr.', 'Mrs.']; ngOnInit(): void { this.importRules = { 'condition': 'and', 'rules': [{ 'label': 'Employee ID', 'field': 'EmployeeID', 'type': 'number', 'operator': 'equal', 'value': 1 }, { 'label': 'Title', 'field': 'Title', 'type': 'string', 'operator': 'equal', 'value': 'Sales Manager' }] }; } }
Screenshot:
Summary
Refer to our documentation and online samples for more features. If you have any queries, please let us know in comments below. You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!
Conclusion
I hope you enjoyed learning about how to get started with Angular 11 QueryBuilder.
You can refer to our Angular
Query Builder tour
page to know
about its other groundbreaking feature representations documentation
and how to quickly get started for configuration
specifications. You can also explore our Angular
Query Builder example
to understand
how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!