Gathering detailed insights and metrics for react-awesome-query-builder
Gathering detailed insights and metrics for react-awesome-query-builder
Gathering detailed insights and metrics for react-awesome-query-builder
Gathering detailed insights and metrics for react-awesome-query-builder
@react-awesome-query-builder/ui
User-friendly query builder for React. Core React UI
@react-awesome-query-builder/core
User-friendly query builder for React. Core
@react-awesome-query-builder/antd
User-friendly query builder for React. AntDesign widgets
@react-awesome-query-builder/mui
User-friendly query builder for React. MUI 5 widgets
npm install react-awesome-query-builder
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (74.37%)
TypeScript (22.52%)
SCSS (2.56%)
Shell (0.51%)
HTML (0.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,125 Stars
902 Commits
523 Forks
31 Watchers
10 Branches
87 Contributors
Updated on Jul 11, 2025
Latest Version
5.4.2
Package Id
react-awesome-query-builder@5.4.2
Unpacked Size
2.70 MB
Size
0.98 MB
File Count
640
NPM Version
6.14.15
Node Version
14.20.1
Published on
Mar 29, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
11
20
91
User-friendly React component to build queries (filters).
Inspired by jQuery QueryBuilder. Using awesome Ant Design v4 for widgets. Now Material-UI is also supported!
See live demo
Install:
npm i react-awesome-query-builder --save
For AntDesign widgets only:
npm i antd @ant-design/icons --save
For Material-UI 4 widgets only:
npm i @material-ui/core @material-ui/lab @material-ui/icons @material-ui/pickers material-ui-confirm@2 --save
For MUI 5 widgets only:
npm i @mui/material @emotion/react @emotion/styled @mui/lab @mui/icons-material @mui/x-date-pickers material-ui-confirm@3 --save
For Bootstrap widgets only:
npm i bootstrap reactstrap @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons @fortawesome/react-fontawesome --save
See basic usage for minimum code example.
See API and config for documentation.
Demo apps:
npm start
- demo app with hot reload of demo code and local library code, uses TS, uses complex config to demonstrate anvanced usage.npm run sandbox-ts
- demo app with hot reload of only demo code (uses latest version of library from npm), uses TS, uses AntDesign widgets.npm run sandbox-js
- demo app with hot reload of only demo code (uses latest version of library from npm), not uses TS, uses vanilla widgets.1import React, {Component} from 'react'; 2import {Query, Builder, BasicConfig, Utils as QbUtils} from 'react-awesome-query-builder'; 3 4// For AntDesign widgets only: 5import AntdConfig from 'react-awesome-query-builder/lib/config/antd'; 6import 'antd/dist/antd.css'; // or import "react-awesome-query-builder/css/antd.less"; 7// For MUI 4/5 widgets only: 8import MaterialConfig from 'react-awesome-query-builder/lib/config/material'; 9import MuiConfig from 'react-awesome-query-builder/lib/config/mui'; 10// For Bootstrap widgets only: 11import BootstrapConfig from "react-awesome-query-builder/lib/config/bootstrap"; 12 13import 'react-awesome-query-builder/lib/css/styles.css'; 14import 'react-awesome-query-builder/lib/css/compact_styles.css'; //optional, for more compact styles 15 16// Choose your skin (ant/material/vanilla): 17const InitialConfig = AntdConfig; // or MaterialConfig or MuiConfig or BootstrapConfig or BasicConfig 18 19// You need to provide your own config. See below 'Config format' 20const config = { 21 ...InitialConfig, 22 fields: { 23 qty: { 24 label: 'Qty', 25 type: 'number', 26 fieldSettings: { 27 min: 0, 28 }, 29 valueSources: ['value'], 30 preferWidgets: ['number'], 31 }, 32 price: { 33 label: 'Price', 34 type: 'number', 35 valueSources: ['value'], 36 fieldSettings: { 37 min: 10, 38 max: 100, 39 }, 40 preferWidgets: ['slider', 'rangeslider'], 41 }, 42 color: { 43 label: 'Color', 44 type: 'select', 45 valueSources: ['value'], 46 fieldSettings: { 47 listValues: [ 48 { value: 'yellow', title: 'Yellow' }, 49 { value: 'green', title: 'Green' }, 50 { value: 'orange', title: 'Orange' } 51 ], 52 } 53 }, 54 is_promotion: { 55 label: 'Promo?', 56 type: 'boolean', 57 operators: ['equal'], 58 valueSources: ['value'], 59 }, 60 } 61}; 62 63// You can load query value from your backend storage (for saving see `Query.onChange()`) 64const queryValue = {"id": QbUtils.uuid(), "type": "group"}; 65 66 67class DemoQueryBuilder extends Component { 68 state = { 69 tree: QbUtils.checkTree(QbUtils.loadTree(queryValue), config), 70 config: config 71 }; 72 73 render = () => ( 74 <div> 75 <Query 76 {...config} 77 value={this.state.tree} 78 onChange={this.onChange} 79 renderBuilder={this.renderBuilder} 80 /> 81 {this.renderResult(this.state)} 82 </div> 83 ) 84 85 renderBuilder = (props) => ( 86 <div className="query-builder-container" style={{padding: '10px'}}> 87 <div className="query-builder qb-lite"> 88 <Builder {...props} /> 89 </div> 90 </div> 91 ) 92 93 renderResult = ({tree: immutableTree, config}) => ( 94 <div className="query-builder-result"> 95 <div>Query string: <pre>{JSON.stringify(QbUtils.queryString(immutableTree, config))}</pre></div> 96 <div>MongoDb query: <pre>{JSON.stringify(QbUtils.mongodbFormat(immutableTree, config))}</pre></div> 97 <div>SQL where: <pre>{JSON.stringify(QbUtils.sqlFormat(immutableTree, config))}</pre></div> 98 <div>JsonLogic: <pre>{JSON.stringify(QbUtils.jsonLogicFormat(immutableTree, config))}</pre></div> 99 </div> 100 ) 101 102 onChange = (immutableTree, config) => { 103 // Tip: for better performance you can apply `throttle` - see `examples/demo` 104 this.setState({tree: immutableTree, config: config}); 105 106 const jsonTree = QbUtils.getTree(immutableTree); 107 console.log(jsonTree); 108 // `jsonTree` can be saved to backend, and later loaded to `queryValue` 109 } 110}
1import React, { useState, useCallback } from "react"; 2import { Query, Builder, Utils as QbUtils } from "react-awesome-query-builder"; 3// types 4import { 5 JsonGroup, 6 Config, 7 ImmutableTree, 8 BuilderProps 9} from "react-awesome-query-builder"; 10 11// For AntDesign widgets only: 12import AntdConfig from "react-awesome-query-builder/lib/config/antd"; 13import "antd/dist/antd.css"; // or import "react-awesome-query-builder/css/antd.less"; 14// For MUI 4/5 widgets only: 15//import MaterialConfig from 'react-awesome-query-builder/lib/config/material'; 16//import MuiConfig from 'react-awesome-query-builder/lib/config/mui'; 17// For Bootstrap widgets only: 18//import BootstrapConfig from "react-awesome-query-builder/lib/config/bootstrap"; 19 20import "react-awesome-query-builder/lib/css/styles.css"; 21import "react-awesome-query-builder/lib/css/compact_styles.css"; //optional, for more compact styles 22 23// Choose your skin (ant/material/vanilla): 24const InitialConfig = AntdConfig; // or MaterialConfig or MuiConfig or BootstrapConfig or BasicConfig 25 26// You need to provide your own config. See below 'Config format' 27const config: Config = { 28 ...InitialConfig, 29 fields: { 30 qty: { 31 label: "Qty", 32 type: "number", 33 fieldSettings: { 34 min: 0 35 }, 36 valueSources: ["value"], 37 preferWidgets: ["number"] 38 }, 39 price: { 40 label: "Price", 41 type: "number", 42 valueSources: ["value"], 43 fieldSettings: { 44 min: 10, 45 max: 100 46 }, 47 preferWidgets: ["slider", "rangeslider"] 48 }, 49 color: { 50 label: "Color", 51 type: "select", 52 valueSources: ["value"], 53 fieldSettings: { 54 listValues: [ 55 { value: "yellow", title: "Yellow" }, 56 { value: "green", title: "Green" }, 57 { value: "orange", title: "Orange" } 58 ] 59 } 60 }, 61 is_promotion: { 62 label: "Promo?", 63 type: "boolean", 64 operators: ["equal"], 65 valueSources: ["value"] 66 } 67 } 68}; 69 70// You can load query value from your backend storage (for saving see `Query.onChange()`) 71const queryValue: JsonGroup = { id: QbUtils.uuid(), type: "group" }; 72 73export const Demo: React.FC = () => { 74 const [state, setState] = useState({ 75 tree: QbUtils.checkTree(QbUtils.loadTree(queryValue), config), 76 config: config 77 }); 78 79 const onChange = useCallback((immutableTree: ImmutableTree, config: Config) => { 80 // Tip: for better performance you can apply `throttle` - see `examples/demo` 81 setState(prevState => { ...prevState, tree: immutableTree, config: config }); 82 83 const jsonTree = QbUtils.getTree(immutableTree); 84 console.log(jsonTree); 85 // `jsonTree` can be saved to backend, and later loaded to `queryValue` 86 }, []); 87 88 const renderBuilder = useCallback((props: BuilderProps) => ( 89 <div className="query-builder-container" style={{ padding: "10px" }}> 90 <div className="query-builder qb-lite"> 91 <Builder {...props} /> 92 </div> 93 </div> 94 ), []); 95 96 return ( 97 <div> 98 <Query 99 {...config} 100 value={state.tree} 101 onChange={onChange} 102 renderBuilder={renderBuilder} 103 /> 104 <div className="query-builder-result"> 105 <div> 106 Query string:{" "} 107 <pre> 108 {JSON.stringify(QbUtils.queryString(state.tree, state.config))} 109 </pre> 110 </div> 111 <div> 112 MongoDb query:{" "} 113 <pre> 114 {JSON.stringify(QbUtils.mongodbFormat(state.tree, state.config))} 115 </pre> 116 </div> 117 <div> 118 SQL where:{" "} 119 <pre> 120 {JSON.stringify(QbUtils.sqlFormat(state.tree, state.config))} 121 </pre> 122 </div> 123 <div> 124 JsonLogic:{" "} 125 <pre> 126 {JSON.stringify(QbUtils.jsonLogicFormat(state.tree, state.config))} 127 </pre> 128 </div> 129 </div> 130 </div> 131 ); 132};
<Query />
Props:
{...config}
- destructured query CONFIG
value
- query value in internal Immutable formatonChange
- callback when query value changed. Params: value
(in Immutable format), config
, actionMeta
(details about action which led to the change, see ActionMeta
in index.d.ts
).renderBuilder
- function to render query builder itself. Takes 1 param props
you need to pass into <Builder {...props} />
.Notes:
useCallback
for onChange
and renderBuilder
for performance reason<Dialog />
or <Popover />
, please:
disableEnforceFocus={true}
for dialog or popver.MuiPopover-root, .MuiDialog-root { z-index: 900 !important; }
(or 1000 for AntDesign v3)<Panel />
, please:
.ms-Layer.ms-Layer--fixed.root-119 { z-index: 900 !important; }
props
arg in renderBuilder
have actions
and dispatch
you can use to run actions programmatically (for list of actions see Actions
in index.d.ts
).<Builder />
Render this component only inside Query.renderBuilder()
like in example above:
1 renderBuilder = (props) => ( 2 <div className="query-builder-container"> 3 <div className="query-builder qb-lite"> 4 <Builder {...props} /> 5 </div> 6 </div> 7 )
Wrapping <Builder />
in div.query-builder
is necessary.
Optionally you can add class .qb-lite
to it for showing action buttons (like delete rule/group, add, etc.) only on hover, which will look cleaner.
Wrapping in div.query-builder-container
is necessary if you put query builder inside scrollable block.
Utils
onChange
callback of <Query>
.light = false
in case if you want to store query value in your state in JS format and pass it as value
of <Query>
after applying loadTree()
(which is not recommended because of double conversion). See issue #190
value
prop to <Query>
(don't forget to also apply checkTree()
).
validateValue
in config, bad ranges) will be deleted if showErrorMessage
is false OR marked with errors if showErrorMessage
is true.
showErrorMessage
in config.settings is true, use this method to check is query has bad values.isForDisplay
= true can be used to make string more "human readable".
errors
, logic
will be rule object and data
will contain all used fields with null values ("template" data).This library uses configarion driven aproach.
Config defines what value types, operators are supported, how they are rendered, imported, exported.
At minimum, you need to provide your own set of fields as in basic usage.
See CONFIG
for full documentation.
Versions 5.x are backward-compatible with 2.x 3.x 4.x.
It's recommended to update your version.
Version | Supported |
---|---|
5.x | :white_check_mark: |
4.x | :white_check_mark: |
3.x | :white_check_mark: |
2.x | :white_check_mark: |
1.x | :warning: |
0.x | :x: |
See CHANGELOG
Breaking change: children1
is now an indexed array (instead of object) in result of Utils.getTree()
to preserve items order.
Before:
1children1: { 2 '<id1>': { type: 'rule', properties: ... }, 3 '<id2>': { type: 'rule', properties: ... } 4}
After:
1children1: [ 2 { id: '<id1>', type: 'rule', properties: ... }, 3 { id: '<id2>', type: 'rule', properties: ... }, 4]
Utils.loadTree()
is backward comatible with children1 being array or object.
But if you rely on previous format (maybe do post-processing of getTree()
result), please use Utils.getTree(tree, true, false)
- it will behave same as before this change.
Version 4.9.0 has a breaking change for operators is_empty
and is_not_empty
.
Now these operators can be used for text type only (for other types they will be auto converted to is_null
/is_not_null
during loading of query value created with previous versions).
Changed meaning of is_empty
- now it's just strict comparing with empty string.
Before change the meaning was similar to is_null
.
If you used is_empty
for text types with intention of comparing with null, please replace is_empty
-> is_null
, is_not_empty
-> is_not_null
in saved query values.
If you used JsonLogic for saving, you need to replace {"!": {"var": "your_field"}}
-> {"==": [{"var": "your_field"}, null]}
and {"!!": {"var": "your_field"}}
-> {"!=": [{"var": "your_field"}, null]}
.
From v2.0 of this lib AntDesign is now optional (peer) dependency, so you need to explicitly include antd
(4.x) in package.json
of your project if you want to use AntDesign UI.
Please import AntdConfig
from react-awesome-query-builder/lib/config/antd
and use it as base for your config (see below in usage).
Alternatively you can use BasicConfig
for simple vanilla UI, which is by default.
Support of other UI frameworks (like Bootstrap) are planned for future, see Other UI frameworks.
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
If you mention in an GitHub issue that you are a sponsor, we will prioritize helping you.
As a sponsor you can ask to implement a feature that is not in a todo list or motivate for faster implementation.
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
MIT. See also LICENSE.txt
Forked from https://github.com/fubhy/react-query-builder
No vulnerabilities found.
Reason
19 commit(s) and 16 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 3
Details
Reason
Found 5/25 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More