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
+72-14Lines changed: 72 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,12 +24,6 @@ function formatQuery(
24
24
- MongoDB
25
25
- Common Expression Language (CEL)
26
26
27
-
:::info
28
-
29
-
The inversion operator (setting `not: true` for a rule group) is currently unsupported for the MongoDB format, but rules can be created using the `"!="` operator.
30
-
31
-
:::
32
-
33
27
For the next few sections, assume the `query` variable has been defined as:
For now, the MongoDB export format has two major shortcomings. For one, it does not support the inversion operator (setting `not: true` for a rule group), however rules _can_ be created using the `"!="` operator. Also, if the query uses [independent combinators](./querybuilder#independentcombinators), it will not be processed and `formatQuery(query, 'mongodb')` will always return the [fallback expression](#fallback-expression).
169
+
170
+
:::
171
+
172
172
### Common Expression Language
173
173
174
174
For Common Expression Language (CEL) output, use the "cel" format.
@@ -185,7 +185,65 @@ Output:
185
185
186
186
## Configuration
187
187
188
-
An object can be passed as the second argument instead of a string in order to have more detailed control over the output.
188
+
An object can be passed as the second argument instead of a string to have more fine-grained control over the output.
189
+
190
+
### Parse numbers
191
+
192
+
Since HTML `<input>` controls store values as strings (even when `type="number"`), exporting a query to various formats may produce a string representation of a value when a true numeric value is required or more appropriate. Set the `parseNumbers` option to `true` and `formatQuery` will attempt to convert all values to numbers, falling back to the original value if `parseFloat(value)` returns `NaN` (not a number).
193
+
194
+
```ts
195
+
const query:RuleGroupType= {
196
+
combinator: 'and',
197
+
not: false,
198
+
rules: [
199
+
{
200
+
field: 'digits',
201
+
operator: '=',
202
+
value: '20',
203
+
},
204
+
{
205
+
field: 'age',
206
+
operator: 'between',
207
+
value: '26, 52',
208
+
},
209
+
{
210
+
field: 'lastName',
211
+
operator: '=',
212
+
value: 'Vai',
213
+
},
214
+
],
215
+
};
216
+
217
+
// Default configuration - all values are strings:
218
+
formatQuery(query, { format: 'sql' });
219
+
// Returns: "(digits = '20' and age between '26' and '52' and lastName = 'Vai')"
220
+
221
+
// `parseNumbers: true` - numeric strings converted to actual numbers:
// Returns: "(digits = 20 and age between 26 and 52 and lastName = 'Vai')"
224
+
```
225
+
226
+
:::info
227
+
228
+
To avoid information loss, this option is more strict about what qualifies as "numeric" than [the standard `parseFloat` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat). Put simply, `parseFloat` works with any string that _starts_ with a numeric sequence, ignoring the rest of the string beginning with the first non-numeric character. When `parseNumbers` is `true`, `formatQuery` will only convert a `value` to a `number` if it appears to be numeric _in its entirety_ (after trimming whitespace).
Copy file name to clipboardExpand all lines: docs/api/querybuilder.mdx
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -735,6 +735,12 @@ Pass `true` to display a drag handle to the left of each group header and rule.
735
735
736
736
Pass `true` to disable all subcomponents and prevent changes to the query. Pass an array of paths to disable specific rules and/or groups, e.g. `disabled={[[0]]}` will disable the first rule and its subcomponents but nothing else.
737
737
738
+
### `debugMode`
739
+
740
+
`boolean` (default `false`) [_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#debugMode=true)
741
+
742
+
Pass `true` to log debugging information to the console.
743
+
738
744
### `validator`
739
745
740
746
`QueryValidator`[_Click for demo_](https://react-querybuilder.github.io/react-querybuilder/#validateQuery=true)
0 commit comments