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

Complex Operators with custom inputs (eg modulo)

Open ascyltos opened this issue 8 years ago • 5 comments

I am looking for a way to implement a modulo operator, but I am not sure what might be the way to do so.

When selecting the modulo op the resulting rule should display something like this (please ignore the first and last select, the image is taken from the current implementation):

image

The idea is to model operations like:

field % value = 5
field % value > 10
....

I've been able to add the modulo operator but all the fields are now shown as inputs for numbers:

(function() {

  var QueryBuilder = jQuery.fn.queryBuilder,
      operators = QueryBuilder.defaults('operators'),
      operatorsAsArray = Object.keys(operators).map(function (key) {return operators[key]});

  operatorsAsArray.push({
    type: 'modulo',
    nb_inputs: 3,
    apply_to: ['number']
  });

  QueryBuilder.defaults({operators: operatorsAsArray});
})();

image

Is there a way to specify custom inputs or a template for an operator?

ascyltos avatar May 03 '16 12:05 ascyltos

No. You can use the filter input and return your special layout when the rule operator is MOD, not very pratical though.

I'll try to implement operator level inputs layout but not imediately.

mistic100 avatar May 03 '16 13:05 mistic100

Ah great, that's a solution at least for now...

Thanks alot!

ascyltos avatar May 03 '16 13:05 ascyltos

How can I use the filter input and return my special layout when the rule operator my custom operator?

Found: https://github.com/mistic100/jQuery-QueryBuilder/issues/251. But rule.filter and rule.operator always undefined ... Thank You.

SarahTrees avatar May 02 '17 12:05 SarahTrees

https://jsfiddle.net/89byg4wh/12/

SarahTrees avatar May 02 '17 13:05 SarahTrees

Could someone share the example of having multiple operators ?

mvksages avatar Apr 03 '24 20:04 mvksages