All Projects → vojtechportes → react-query-builder

vojtechportes / react-query-builder

Licence: MIT License
Simple, configurable react query builder

Programming Languages

typescript
32286 projects
HTML
75241 projects

Projects that are alternatives of or similar to react-query-builder

querqy-elasticsearch
Querqy for Elasticsearch
Stars: ✭ 37 (+0%)
Mutual labels:  query, query-builder, querybuilder
Sqliterally
Lightweight SQL query builder
Stars: ✭ 231 (+524.32%)
Mutual labels:  query, query-builder
Pecee Pixie
Lightweight, easy-to-use querybuilder for PHP inspired by Laravel Eloquent - but with less overhead.
Stars: ✭ 19 (-48.65%)
Mutual labels:  query, query-builder
searchable
Pattern-matching search and reusable queries in laravel.
Stars: ✭ 28 (-24.32%)
Mutual labels:  query, query-builder
React Querybuilder
A QueryBuilder component for React
Stars: ✭ 315 (+751.35%)
Mutual labels:  query, query-builder
Laravel Eloquent Query Cache
Adding cache on your Laravel Eloquent queries' results is now a breeze.
Stars: ✭ 529 (+1329.73%)
Mutual labels:  query, query-builder
flepper
Flepper is a library to aid in database interaction. 🐸
Stars: ✭ 60 (+62.16%)
Mutual labels:  query-builder, querybuilder
SimplePHP
A small query builder project designed to assist daily routines and speed up the process of communicating with the database.
Stars: ✭ 14 (-62.16%)
Mutual labels:  query, querybuilder
AdvancedSQL
The best Java query builder/SQL connector.
Stars: ✭ 23 (-37.84%)
Mutual labels:  query, query-builder
uri-query-parser
a parser and a builder to work with URI query string the right way in PHP
Stars: ✭ 38 (+2.7%)
Mutual labels:  query, query-builder
Loukoum
A simple SQL Query Builder
Stars: ✭ 305 (+724.32%)
Mutual labels:  query, query-builder
vaultaire
Query DSL and data access utilities for Corda developers.
Stars: ✭ 14 (-62.16%)
Mutual labels:  query, query-builder
sql-concat
A MySQL query builder
Stars: ✭ 14 (-62.16%)
Mutual labels:  query, query-builder
active-persistence
Active Persistence is a implementation of Active Record Query Interface for JPA that makes it easy and fun.
Stars: ✭ 14 (-62.16%)
Mutual labels:  query, query-builder
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+905.41%)
Mutual labels:  query, query-builder
json-sql-builder2
Level Up Your SQL-Queries
Stars: ✭ 59 (+59.46%)
Mutual labels:  query, query-builder
apex-query-builder
Convenient query builder for dynamic SOQL queries
Stars: ✭ 37 (+0%)
Mutual labels:  query, query-builder
TIL
Today I Learned
Stars: ✭ 43 (+16.22%)
Mutual labels:  query
ethjs-rpc
A super simple module for making low level queries to the Ethereum RPC layer.
Stars: ✭ 14 (-62.16%)
Mutual labels:  query
mctools
Minecraft Connection Tools - Python implementations of common Minecraft protocols.
Stars: ✭ 27 (-27.03%)
Mutual labels:  query

ℹ️ RFC 1.x.x

Please note that right now I am planning to start working on version 1.x.x. It will involve lot of refactoring, new features and some breaking changes. I will try to introduce ways how to keep things backwards compatible though.

If you are interested, check #37 for RFC and let me know what you think and what new features you would welcome.


React Query Builder

Simple, highly configurable query builder
for React written in TypeSript

npm version License: MIT Travis CI Status Coverage Status DeepScan grade




Installation

npm install @vojtechportes/react-query-builder

or

yarn add @vojtechportes/react-query-builder

Demo

with examples of field definition and custom components...
...or check source code on GitHub

React Query Builder


Usage

import React from 'react';
import {
  Builder,
  BuilderFieldProps,
  BuilderComponentsProps,
} from 'react-query-builder';

const fields: BuilderFieldProps[] = [
  // Fields configuration
];

const data: any = [
  // Initial query tree
];

const components: BuilderComponentsProps = {
  // Custom components configuration
};

const MyBuilder: React.FC = () => (
  <Builder
    readOnly={false}
    fields={fields}
    data={data}
    components={components}
    onChange={data => console.log(data)}
  />
);

Configuration

Since React Query Builder is highly configurable, you can define look of the Query Builder, you can define and use your own components, set whether the Builder should be readOnly or not and of course, you will need to set up fields Query Builder will be using.

Lets start with fields...

import { BuilderFieldProps } from 'react-query-builder';

const fields: BuilderFieldProps[] = [
    {
        field: 'STATE',
        label: 'State',
        type: 'LIST',
        operators: ['EQUAL', 'NOT_EQUAL'],
        value: [
            { value: 'CZ', label: 'Czech Republic' },
            { value: 'SK', label: 'Slovakia' },
            { value: 'PL', label: 'Poland' },
        ],
    },
    {
        field: 'IS_IN_EU',
        label: 'Is in EU',
        type: 'BOOLEAN'
    }
];

As you can see, there are few things you can define. field, label, type, operators and value.

Field

Field is a key and needs to be unique, since it is used to reference field in query tree as you will see further down in documentation.

Label

Label is pretty obvious, so lets skip to type.

Type

Type can be any of following constants:

BOOLEAN
TEXT
DATE
NUMBER
STATEMENT
LIST
MULTI_LIST
GROUP (*)

* GROUP type is not intended to be used in field props definition but only in data object.

Operators

Operator can be array of following constants

LARGER
SMALLER
LARGER_EQUAL
SMALLER_EQUAL
EQUAL
NOT_EQUAL
ALL_IN
ANY_IN
NOT_IN
BETWEEN
NOT_BETWEEN
LIKE
NOT_LIKE

Value

Value can be either string (STATEMENT) or array of objects with value and label keys (LIST, MULTI_LIST). Values for other types are empty by default.

Data

Data can be either empty array or array of rules and groups.

[
    {
        "type": "GROUP",
        "value": "AND",
        "isNegated": false,
        "children": [
            {
                "field": "IS_IN_EU", // <- Type here is refering to field property in fields configuration
                "value": false
            }
        ]
    }
]

Components

Components is set of components you can use to customize React Query Builder. You can either just style them using styled-components or use your own components as long as they follow typings of original components.

You can customize following componetns

Select
SelectMulti
Switch
Input
Remove
Add
Component
Group
GroupHeaderOption

via config object

const components: BuilderComponentsProps = {
  form: {
    Select: MyCustomSelect,
    SelectMulti: MyCustomSelectMulti,
    Switch: MyCustomSwitch,
    Input: MyCustomInput,
  },
  Remove: MyCustomRemove,
  Add: MyCustomAdd,
  Component: MyCustomComponent,
  Group: MyCustomGroup,
  GroupHeaderOption: MyCustomHeaderOption,
};

onChange

onChange property is allowing you to retrieve query tree after every change that occures in React Query Builder.


Localization

To either use custom strings or localize ReactBuilder, you can use strings property on Builder component.

You can work with object of following format:

const strings: Strings = {
  "group": {
    "not": "Not",
    "or": "Or",
    "and": "And",
    "addRule": "Add Rule",
    "addGroup": "Add Group",
    "delete": "Delete"
  },
  "components": {
    "delete": "Delete"
  },
  "form": {
    "selectYourValue": "Select your value"
  },
  "operators": {
    "LARGER": "Larger",
    "SMALLER": "Smaller",
    "LARGER_EQUAL": "Larger or equal",
    "SMALLER_EQUAL": "Smaller or equal",
    "EQUAL": "Equal",
    "NOT_EQUAL": "Not equal",
    "ALL_IN": "All in",
    "ANY_IN": "Any in",
    "NOT_IN": "Not in",
    "BETWEEN": "Between",
    "NOT_BETWEEN": "Not between"
  }
};

It is not required to translate all the strings. Strings that are not specified by you will be loaded from default strings.

To work with multiple locales, you can use for example amazing i18next framework.

import React from 'react';
import { Builder, Strings } from '@vojtechportes/react-query-builder';
import { Trans, useTranslation } from 'react-i18next';

export const QueryBuiler:React.FC = () => {
  useTranslation('query-builder')

  const strings: Strings = {
    operators: {
      LARGER: <Trans ns="query-builder" i18nKey="larger" />,
      SMALLER: <Trans ns="query-builder" i18nKey="smaller" />
      /* And so on */
    }
  };

  return (
    <Builder
      strings={strings}
      fields={fields}
      data={[]}
      onChange={(data: any) => console.log(data)} 
      />
  );
};

#Feature development

Please check #37

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].