Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-awesome-query-builder

> 前端框架
Open source

User-friendly query builder for React

2.3K stars0 likes3 views
WebsiteGitHub

About

User-friendly query builder for React

User-friendly React component to build queries (filters).

Inspired by jQuery QueryBuilder. Using awesome UI frameworks for widgets: Ant Design, Material-UI, Bootstrap. Now Fluent UI is also supported!

See live demo

  • Features
  • Getting started
  • Demo apps
  • Usage
    • Minimal JavaScript example with class component
    • Minimal TypeScript example with function component
  • API
    • Query
    • Builder
    • Utils
      • Save/load tree
      • Validation utils
      • Export
      • Import
      • Save/load config from server
    • Config format
    • Validation
  • i18n
  • Ternary mode
  • SSR
    • ctx
  • Versions
    • Changelog
    • Migration to 6.5.0
    • Migration to 6.4.0
    • Migration to 6.3.0
    • Migration to 6.2.0
    • Migration to 6.0.0
    • Migration to 5.2.0
    • Migration to 4.9.0
    • Migration from v1 to v2
  • Contributing
    • Code Contributing
    • Financial Contributing

React-Awesome-Query-Builder AI Bot

React-Awesome-Query-Builder Bot will help you understand this repository better. You can ask for code examples, installation guide, debugging help and much more.

Features

  • Highly configurable. You can configure fields, types, operators, functions, widgets, behavior settings etc.
  • Fields can have simple type (string, number, bool, date/time, list), custom or complex (structs, arrays)
  • Aggregation is supported (query like "COUNT OF users WHERE (role == 'Manager' AND department == 'Development') > 5")
  • Fields can be compared with other fields
  • Comparison operators can be: binary (== != < >), unary ('is null'), 'between' or complex operators like 'proximity'
  • Functions are supported in both LHS and RHS. Functions nesting is supported (function argument can be a function)
  • Ternary mode (if-then-else)
  • Export to MongoDb, SQL, JsonLogic, SpEL, ElasticSearch or your custom format
  • Import from JsonLogic, SpEL, SQL
  • Reordering (drag-n-drop) support for rules and groups of rules
  • Query value and config can be saved/loaded from server
  • Themes: Ant Design, Material-UI, Bootstrap, Fluent UI, vanilla It is possible to use another UI framework of your choice, see how-to
  • TypeScript support (see types and demo in TS)

Getting started

From v6 library is divided into packages:

  • @react-awesome-query-builder/core - has core functionality to import/export/store query, provides utils
  • @react-awesome-query-builder/ui - has core React components like <Query> <Builder> and CSS, provides config with basic (vanilla) widgets
  • @react-awesome-query-builder/antd - provides config with Ant Design widgets
  • @react-awesome-query-builder/mui - provides config with MUI widgets
  • @react-awesome-query-builder/material - provides config with Material-UI v4 widgets (deprecated)
  • @react-awesome-query-builder/bootstrap - provides config with Bootstrap widgets
  • @react-awesome-query-builder/fluent - provides config with Fluent UI widgets
mermaid
graph LR;
  core-->ui;
  core-->sql((sql));
  ui-->antd;
  ui-->mui;
  ui-->material;
  ui-->bootstrap;
  ui-->fluent;

ui re-exports from core, other packages re-export from ui. For using this library on frontend you need to install and use only ui (for basic widgets) or one of framework-specific packages (antd / mui / bootstrap / fluent).

For using this library on server-side (Node.js) you need only core. This is useful if you want to pass query value from frontend to backend in JSON format and perform export eg. to SQL on server-side for security reasons.

Example of installation if you use MUI:

bash
npm i @react-awesome-query-builder/mui --save

Note: We use pnpm. If you want to clone this project and run scripts, please install pnpm:

bash
npm install -g pnpm

See basic usage for minimum code example.

See API and config for documentation.

Demo apps

  • pnpm start - demo app with hot reload of demo code and local library code, uses TS, uses complex config to demonstrate anvanced usage, uses all supported UI frameworks.
  • pnpm sandbox-ts - simple demo app, built with Vite, uses TS, uses MUI widgets.
  • pnpm sandbox-js - simplest demo app, built with Vite, not uses TS, uses vanilla widgets.
  • pnpm sandbox-next - advanced demo app with server side, built with Next.js, uses TS, uses MUI widgets, has API to save/load query value and query config from storage.

Usage

Minimal JavaScript example with class component

…

Minimal TypeScript example with function component

…

API

<Query />

Props:

  • {...config} - destructured CONFIG
  • value - query value in internal Immutable format
  • onChange - callback called when query value changes. Params: value (in Immutable format), config, actionMeta (details about action which led to the change, see ActionMeta in index.d.ts), actions (you can use to run actions programmatically, see Actions in index.d.ts).
  • onInit - callback called before initial render, has same arguments as onChange (but actionMeta is undefined)
  • renderBuilder - function to render query builder itself. Takes 1 param props you need to pass into <Builder {...props} />.

Notes:

  • Please apply useCallback for onChange and renderBuilder for performance reason
  • If you put query builder component inside Material-UI's <Dialog /> or <Popover />, please:
    • use prop disableEnforceFocus={true} for dialog or popver
    • set css .MuiPopover-root, .MuiDialog-root { z-index: 900 !important; } (or 1000 for AntDesign v3)
  • If you put query builder component inside Fluent-UI's <Panel />, please:
    • set css .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 a list of available actions see Actions interface in index.d.ts. See runActions() in examples as a demonstration of calling actions programmatically.

<Builder />

Render this component only inside Query.renderBuilder() like in example above:

javascript
  renderBuilder = (props) => (
    

    </div>
  )

Wrapping <Builder /> in div.query-builder is necessary for drag-n-drop support.
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 for correct drag-n-drop support if you put query builder inside scrollable block.

Utils

Save/load tree

getTree

Utils.getTree (immutableValue, light = true, children1AsArray = true) -> Object
Convert query value from internal Immutable format to JS object.
You can use it to save value on backend in onChange callback of <Query>.
Tip: Use 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

loadTree

Utils.loadTree (jsValue) -> Immutable
Convert query value from JS format to internal Immutable format.
You can use it to load saved value from backend and pass as value prop to <Query>.

Validation utils

isValidTree

Utils.isValidTree (immutableValue, config) -> Boolean
If showErrorMessage in config.settings is true, use this method to check if query has validation errors (presented in UI with red text color under the rule).
Note that incomplete rules or empty groups are not counted as validation errors for this function.
If showErrorMessage is false, this function will always return true.

validateTree

Utils.validateTree (immutableValue, config, options?) -> Array
Validates immutable query value to check it corresponds to the config and has no parts that are invalid or incomplete.
Returns array of errors grouped by item in tree.
Each array element is { itemStr, itemPositionStr, errors, path } (see type ValidationItemErrors).

To present item for user you can use itemStr (string representation of rule eg. Number > 55) and itemPositionStr (eg. Rule #4 (index path: 1, 2)).
Also you can use path to get raw item data with Utils.TreeUtils.getItemByPath(tree, path) (advanced).

errors is an array of objects { str, key, args, side, delta } (see type ValidationError).
str is an error message translated with i18next.t(key, args) (namespace is raqbvalidation).
side can be one of rhs or lhs.
delta can be 0 or 1 for between operator.

You can override/extend translations with:
Utils.i18n.addResources("en", "raqbvalidation", { ...yourTranslations })
See default validation translations.
See i18n for validation.

sanitizeTree

Utils.sanitizeTree (immutableValue, config, options?) -> { fixedTree, fixedErrors, nonFixedErrors }
Validates and modifies immutable query value to ensure it corresponds to the config and has no parts that are invalid or incomplete.
Invalid rules (eg. if field is not found in config) will always be deleted.
Invalid values (eg. value > max or < min, value not passing validateValue() in field config) will be either:

  • always deleted if showErrorMessage in config.settings is false
  • fixed (i

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptant-designantdantdesignfilter

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架