jQuery-QueryBuilder
jQuery-QueryBuilder copied to clipboard
Complex Operators with custom inputs (eg modulo)
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):
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});
})();
Is there a way to specify custom inputs or a template for an operator?
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.
Ah great, that's a solution at least for now...
Thanks alot!
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.
https://jsfiddle.net/89byg4wh/12/
Could someone share the example of having multiple operators ?