mistic100 / jQuery-QueryBuilder

jQuery plugin offering an interface to create complex queries

Home Page:https://querybuilder.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can you add rules dynamically?

LEarwax opened this issue · comments

I'm really struggling to get this to work.

Basically, I'm trying to leverage the addRule method so that when a user selects a particular option, the rule (i.e. left hand value) is created and populated with a number of select options. The trouble I'm having is that I can't seem to invoke the method.

I'm initializing it like so:

`this.queryBuilder = $('#builder-basic').queryBuilder({

  filters: [{
    id: '-',
    label: '-',
    type: 'integer',
    input: 'select',
    values: {
      // Will be ArtifactID: TextIdentifier e.g. 12432432: 'Relevant'
    },
    operators: constants.OPERATORS
  }, {
    id: 'review_relevance',
    label: 'Review Relevance',
    type: 'integer',
    input: 'select',
    values: constants.TEST_FILTER_VALUES
  }
],
  conditions: ['AND', 'OR', 'XOR'],
  // rules: rules_basic
});

`

And I'm trying to call like this:

this.queryBuilder.addRule( { <my rule options> } )

I know I'm making a stupid mistake somewhere.

I've been experimenting with this today and I've figured out what I really want to do. I want to first, initialize the builder on page load. And then the user will select an option which will in turn affect the rules they can choose. So what I really need to be able to do is completely recreate the builder with different filters. I've tried resetting (which just resets with the filters that are provided upon page load init) and I've tried using destroy, which seems to do more or less the same thing.

To outline what I did, I call the destroy method:

$('#builder-basic').queryBuilder('destroy');

Which completely removes the queryBuilder. Once the data I am going to use is fetched from the server, I format it as queryBuilder Filter, and then I reinitialize the queryBuilder with the new Filters.

this.queryBuilder = $('#builder-basic').queryBuilder({
filters: myNewfilters,
conditions: ['AND', 'OR', 'XOR'],
});