mistic100 / jQuery-QueryBuilder

jQuery plugin offering an interface to create complex queries
https://querybuilder.js.org
MIT License
1.68k stars 552 forks source link

Custom type or how to use valueGetter #943

Open Blackbaud-JasonBodnar opened 2 years ago

Blackbaud-JasonBodnar commented 2 years ago

I'm using QueryBuilder to create queries for a MongoDB collection. One of the fields in the documents in the collection is amount and it's defined as Decimal128. In order to query it the value needs to be wrapped in NumberDecimal() like:

db.getCollection('transactions').find({"$and":[{"amount":NumberDecimal(99.02)}]})

Is it possible to create a custom type to QueryBuilder applies this to fields where this is necessary?

I tried using valueGetter but it's not working. My filter looks like:

{
  id: 'amount',
  type: 'double',
  valueGetter: (rule) => {
    return `NumberDecimal(${rule.$el.find('[name*=_value_]').val()})`
  }
}

If I debug the valueGetter it's returning what I would expect (NumberDecimal(99.02)) but when I get the rules I get null.

I guess I could change the type to string but then I'd also have to change all the operators to the numeric operators.

Is there a better way to do this?