jQuery-QueryBuilder icon indicating copy to clipboard operation
jQuery-QueryBuilder copied to clipboard

Custom type or how to use valueGetter

Open Blackbaud-JasonBodnar opened this issue 3 years ago • 0 comments

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?

Blackbaud-JasonBodnar avatar Jan 31 '22 23:01 Blackbaud-JasonBodnar