Introducing New React Query Builder UI Component | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (163).NET Core  (29).NET MAUI  (83)Angular  (82)ASP.NET  (50)ASP.NET Core  (79)ASP.NET MVC  (88)Azure  (38)Blazor  (160)DocIO  (23)Essential JS 2  (89)Essential Studio  (180)File Formats  (33)Flutter  (123)JavaScript  (190)Microsoft  (114)PDF  (68)React  (65)Succinctly series  (129)Syncfusion  (638)TypeScript  (32)Uno Platform  (3)UWP  (4)Vue  (40)Webinar  (35)Windows Forms  (59)WinUI  (56)WPF  (140)Xamarin  (157)XlsIO  (26)Other CategoriesBarcode  (5)BI  (29)Bold BI  (5)Build conference  (6)Business intelligence  (54)Button  (4)C#  (121)Chart  (59)Cloud  (13)Company  (445)Dashboard  (8)Data Science  (3)Data Validation  (6)DataGrid  (56)Development  (420)Doc  (7)DockingManager  (1)eBook  (97)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (24)Extensions  (19)File Manager  (4)Gantt  (14)Gauge  (11)Git  (4)Grid  (28)HTML  (12)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (336)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (33)Performance  (10)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (8)Road Map  (11)Scheduler  (39)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (23)Solution Services  (3)Spreadsheet  (11)SQL  (8)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (96)UI  (240)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (23)Visual Studio Code  (17)Web  (398)What's new  (229)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
React Query builder

Introducing New React Query Builder UI Component

Syncfusion has recently added the Query Builder UI component to our React UI components library. It’s a great tool to help you construct and display complex filtering queries. This blog will provide an overview of the React Query Builder UI component, and shows you its basic usage and features, step by step.

React Query Builder UI componentReact Query builder UI component

The Query Builder UI combined with Grid performs advanced searching and displays the results in an organized manner. It is fully customizable to include many input components like slider, drop-down list, multi-select, and check boxes for value selection.

Get started with Query Builder UI

Here, we can see step by step procedure to get started with the Query Builder UI component in the React platform:

  1. First, we need to use the create-react-app CLI. If you don’t have the CLI, then, install it globally using following command.
    npm install -g create-react-app
  2. Create a React application and download its dependencies using the following command.
    create-react-app querybuilder --scripts-version=react-scripts-ts
  3. Now, install the packages for including Query Builder UI component into your application, using the following command.
    cd querybuilder
    npm install @syncfusion/ej2-react-querybuilder
  4. With this we have completed the environment related configurations. Next, to include the Query Builder UI component in the application, import the same from ej2-react-querybuilder package in App.tsx.
    import {QueryBuilderComponent} from '@syncfusion/ej2-react-querybuilder';
  5. Syncfusion React UI components support a set of built-in themes, and here we will use the Material theme for our query builder. To add the Material theme to your application, you need to import material.css into App.css.
    @import "";
  6. With this, we have successfully completed the configurations related to the Query Builder UI component. Now we should initialize our first query builder in TSX as shown in the following code example.
    class App extends React.Component {
    public render() {
    return (<div > <QueryBuilderComponent /> </div>);
  7. Finally, run the following command to see the output in a browser.
npm start

Query builder Query Builder UI

Data binding

The Query Builder UI component uses DataManager, which supports both RESTful JSON data service binding and local JavaScript object array binding. The dataSource property of the query builder can be assigned with a JavaScript object array collection.

All the columns defined in the dataSource will be auto-populated using the data source schema. If all the columns defined are not required, then, we can manually define the fields using the columns property.

Now, define the employee table and map it to the dataSource of our query builder.

const hardwareData: object[] = [
{"TaskID": 1, "Name": "Lenovo Yoga", "Category": "Laptop",
"SerialNo": "CB27932009", "InvoiceNo": "INV-2878", "Status": "Assigned"  },
{"TaskID": 2, "Name": "Acer Aspire", "Category": "Others",
"SerialNo": "CB35728290", "InvoiceNo": "INV-3456", "Status": "In-repair" },

class App extends React.Component {
public render() {
return (<div ><QueryBuilderComponent dataSource={ hardwareData } /></div>);

After binding the data, the query builder will be rendered based on the data.

data binding in query builderData binding in Query Builder UI

Defining columns

The Query Builder UI component has flexible APIs to define the column label, type, format, and operators:

labelField values are considered labels by default, and we can further customize them using this property.

typeDefines the data type of the column.

formatCustomizes the format of date and number column types.

operatorsCustomizes the default operators for the column.

The following code example imports the ColumnsModel from the ej2-react-querybuilder package in App.tsx and customizes the label and type.

import {ColumnsModel, QueryBuilderComponent} from '@syncfusion/ej2-react-querybuilder';
class App extends React.Component {
public columnData: ColumnsModel[] = [
{field: 'TaskID', label: 'TaskID', type: 'number', 
operators: [{ key: 'equal', value: 'equal' },
{ key: 'greaterthan', value: 'greaterthan' }, { key: 'lessthan', value: 'lessthan' }]
{ field: 'Name', label: 'Name', type: 'string' },
{ field: 'Category', label: 'Category', type: 'string' },
{ field: 'SerialNo', label: 'SerialNo', type: 'string' },
{ field: 'InvoiceNo', label: 'InvoiceNo', type: 'string' },
{ field: 'Status', label: 'Status', type: 'string' }

public render() {
return (<div ><QueryBuilderComponent dataSource={employeeData} columns={this.columnData} /></div>);

defining columns in query builder UI Defining columns in Query Builder UI

Binding the filter query to Grid

In this segment, we are going to add a grid component and populate it with the search result from the query builder. For this, we need to install the Syncfusion React Grid and Syncfusion React Button packages.

npm install @syncfusion/ej2-react-grids @syncfusion/ej2-react-buttons

Now, bind the data and configure the columns of the grid. Initialize DataManager with hardwareData, which is defined as the dataSource of Query Builder UI component. Define the query to get the required data from the hardware data and assign it to the Grid component’s query property.

import { DataManager, Predicate, Query } from '@syncfusion/ej2-data';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { ColumnDirective, ColumnsDirective, GridComponent, Inject, Page } from '@syncfusion/ej2-react-grids';
public datamanager: DataManager = new DataManager(hardwareData);
public query: Query = new Query().select(['TaskID', 'Name', 'Category', 'SerialNo', 'InvoiceNo', 'Status']);
<GridComponent allowPaging={true} dataSource={this.datamanager} width='100%'
ref={(scope) => { this.gridObj = scope; }} query={this.query} >
<ColumnDirective field='TaskID' headerText='Task ID' width='120' textAlign='Right' />
<ColumnDirective field='Name' headerText='Name' width='140' />
<ColumnDirective field='Category' headerText='Category' width='140' textAlign='Right' />
<ColumnDirective field='SerialNo' headerText='Serial No' width='130' />
<ColumnDirective field='InvoiceNo' headerText='Invoice No' width='120' />
<ColumnDirective field='Status' headerText='Status' width='120' />
<Inject services={[Page]} />

Finally, synchronize the filter changes in our query builder to populate the filtered data into our grid. For this, we need to detect the query changes and update the grid query to refresh the filtered data by handling the button click event.

<QueryBuilderComponent width='100%' dataSource={hardwareData} columns={this.columnData} ref={(scope) => { this.qryBldrObj = scope; }} />
<ButtonComponent onClick={this.updateRule()} >Filter Grid</ButtonComponent>
public updateRule = ()=>() => {
const predicate: Predicate = this.qryBldrObj.getPredicate({ condition: this.qryBldrObj.rule.condition, rules: this.qryBldrObj.rule.rules });
if (isNullOrUndefined(predicate))
{ this.gridObj.query = new Query().select(['TaskID', 'Name', 'Category', 'SerialNo', 'InvoiceNo', 'Status']); }
{ this.gridObj.query = new Query().select(['TaskID', 'Name', 'Category', 'SerialNo', 'InvoiceNo', 'Status']).where(predicate); }

Now our query builder will look like the below screenshot, with a grid component. You can now create your own complex filter queries and click the filter grid button to see the results.

Binding Query builder filter result to grid Binding query builder filter result to grid


The Query Builder UI component is designed to be highly customizable, to include various input components like slider, multi-select, checkbox, and drop-down lists. This way, input can be received in different formats, to create complex queries.

To try our Query Builder UI component, please download our free trial. You can also check its source from GitHub. For the better use of the component you can check our online sample browser and documentation.

If you have any questions or need any clarification, then, please let us know in the comments section below. You can also contact us through our support forum, Support Portal or Feedback portal. We are always happy to assist you!

If you like this blog post, then we think you’ll also like the following free ebooks,


Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top