You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/export.mdx
+46-3Lines changed: 46 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,49 @@ const query: RuleGroupType = {
50
50
};
51
51
```
52
52
53
+
:::tip
54
+
55
+
_<abbrtitle="Too long; didn't read">TL;DR</abbr>: For best results, use the [default combinators and operators](./misc#defaults) or map custom combinators/operators to the defaults with [`transformQuery`](./misc#transformquery)._
56
+
57
+
While `formatQuery` technically accepts query objects of type `RuleGroupTypeAny` (i.e. `RuleGroupType` or `RuleGroupTypeIC`), it is not guaranteed to process a query correctly unless the query also conforms to the type `DefaultRuleGroupTypeAny` (i.e. `DefaultRuleGroupType` or `DefaultRuleGroupTypeIC`).
58
+
59
+
In practice, this means that all `combinator` and `operator` properties in the query must match the `name` of an element in [`defaultCombinators` or `defaultOperators`](./misc#defaults), respectively. If you implement custom combinator/operator names, you can use the [`transformQuery` function](./misc#transformquery) to map your query properties to the defaults.
60
+
61
+
For example, assume your implementation replaces the default "between" operator (`{ name: "between", label: "between" }`) with `{ name: "b/w", label: "b/w" }`. Any rules using this operator would have `operator: "b/w"` instead of `operator: "between"`. So if a query looked like this...
62
+
63
+
```json
64
+
{
65
+
"combinator": "and",
66
+
"rules": [
67
+
{
68
+
"field": "someNumber",
69
+
"operator": "b/w",
70
+
"value": "12,14"
71
+
}
72
+
]
73
+
}
74
+
```
75
+
76
+
...you could run it through `transformQuery` with the `operatorMap` option:
Copy file name to clipboardExpand all lines: docs/api/querybuilder.mdx
+38-2Lines changed: 38 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ If the `independentCombinators` prop is provided, then the `query` argument will
101
101
102
102
`RuleGroupTypeAny`
103
103
104
-
The query is an object of type `RuleGroupType` (or `RuleGroupTypeIC`, if [`independentCombinators`](#independentCombinators) is `true`). If this prop is provided, `<QueryBuilder />` will be a controlled component.
104
+
The query is an object of type `RuleGroupType` (or `RuleGroupTypeIC`, if [`independentCombinators`](#independentcombinators) is `true`). If this prop is provided, `<QueryBuilder />` will be a controlled component.
105
105
106
106
The `query` prop follows the same format as the parameter passed to the [`onQueryChange`](#onquerychange) callback since they are meant to be used together to control the component. See [examples](https://github.com/react-querybuilder/react-querybuilder/blob/main/examples).
107
107
@@ -720,11 +720,47 @@ Pass `false` to automatically add an "empty" option with value `"~"` and label `
720
720
721
721
Pass `true` to automatically add a rule to new groups. If a `query` prop is not passed in, a rule will be added to the root group when the component is mounted. If a `query` prop is passed in with an empty `rules` array, no rule will be added automatically.
722
722
723
+
### `listsAsArrays`
724
+
725
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#listsAsArrays=true)
726
+
727
+
Pass `true` to update rule values that represent lists with proper arrays instead of comma-separated strings. Applies when `valueEditorType` is "multiselect" and when a rule's `operator` is "between", "notBetween", "in", or "notIn".
728
+
729
+
For example, the default behavior for the "between" operator might produce this rule:
730
+
731
+
```json {4}
732
+
{
733
+
"field": "f1",
734
+
"operator": "between",
735
+
"value": "f2,f3",
736
+
"valueSource": "field"
737
+
}
738
+
```
739
+
740
+
When `listsAsArrays` is true, the rule's `value` will be an array:
741
+
742
+
```json {4}
743
+
{
744
+
"field": "f1",
745
+
"operator": "between",
746
+
"value": ["f2", "f3"],
747
+
"valueSource": "field"
748
+
}
749
+
```
750
+
723
751
### `independentCombinators`
724
752
725
753
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.js.org/react-querybuilder/#independentCombinators=true)
726
754
727
-
Pass `true` to insert an independent combinator selector between each rule/group in a rule group. The combinator selector at the group level will not be available. Visually, this is similar to the [`showCombinatorsBetweenRules`](#showcombinatorsbetweenrules) option, except that each combinator selector is independently controlled. You may find that users take to this configuration more easily, as it can allow them to express queries more like they would in natural language.
755
+
Pass `true` to insert an independent combinator selector between each rule/group in a rule group. The combinator selector at the group level will not be rendered.
756
+
757
+
Visually, this option has a similar effect as the [`showCombinatorsBetweenRules`](#showcombinatorsbetweenrules) option, except that each combinator selector is independently controlled. You may find that users take to this configuration more easily, as it can allow them to express queries more like they would in natural language.
758
+
759
+
:::caution
760
+
761
+
When the `independentCombinators` option is enabled, the `query` (or `defaultQuery`) prop _must_ be of type `RuleGroupTypeIC` instead of the default `RuleGroupType`. See [`onQueryChange`](#onquerychange) above, or the [Rules and groups section](../typescript#rules-and-groups) of the TypeScript documentation for more information.
0 commit comments