Support for simple arithmetic on fields?
See original GitHub issueI love this library and the love that’s gone into writing and maintaining it!
Has anyone ever suggested adding support for simple arithmetic expressions for numeric fields with field
value source, so that we could express rules like Price < 1.05 * YesterdayPrice
(where Price
and YesterdayPrice
are both numeric fields)?
I’m currently interested in linear scaling (a * Field
) but no doubt others may be interested in additive (b + Field
) and affine (a * Field + b
) transforms, for constants a
and b
that the user specifies in Query Builder (you might decide to limit the complexity of these transforms the library supports).
I can very well imagine writing a custom ValueEditor
which renders an input for the constants and a dropdown for the field selector, but how would that be represented in RuleType
, and how much work would it be to export that in SQL/CEL?
(Ideally this would also support between
/notBetween
(per discussion in issue 215), so we could have rules like Price BETWEEN BestBid * 0.99 AND BestAsk * 1.01
, though this isn’t critical since users can always convert between
to a rule group consisting of two rules.)
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:14 (14 by maintainers)
By the way, I just put up PR #320 to add a
parseJsonLogic
function that converts JsonLogic objects to RQB’sRuleGroupType
.Great! I’m glad that worked out. I’ve even got my own use cases for
transformQuery
at work so it was good to get that added.Since you’re clearly an advanced user and really seem to “get” the library, I would encourage you to submit any ideas you may have for the Tips & Tricks pages. The tracking issue on the docs repo has some yet-to-be-documented ideas: react-querybuilder/react-querybuilder.github.io#2.