mistic100 / mistic100/jQuery-QueryBuilder

Custom type or how to use valueGetter

Open
#943 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.7k
Forks
544
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the QueryBuilder type configuration and the valueGetter entry point shown in the issue, then trace how rules are serialized after valueGetter returns. Reproduce the amount filter with the MongoDB output, and consider the work complete when a Decimal128 value is preserved as NumberDecimal(...) while numeric operators remain available.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.