Would it be possible to activate an option in numeric filter so when you enter "20", the values shown are "20" and "-20"?
Huch? This is a bit confusing. In general you can solve all this if you enable ctools module and add the global: math field.
This allows you to apply some formulas to it, and based on this there is no problem to run abs() aor whatever you need.
I haven't tried ctools; I was asking for views to generate a query similar to:
SELECT * FROM ... WHERE abs(numeric_field) = %f
So this is not really working.
It's cool if you could actually now what the people want.
Unfortunately, Views does not currently provide a feature to do this. Doing so would require a custom handler or query modification. Views is unlikely to provide a feature like this.
Ok, I have coded a custom handler:
class views_handler_filter_force_absolute_float extends views_handler_filter_float { function op_between($field) { if ($this->operator == 'between') { $this->query->add_where($this->options['group'], "ABS($field) >= %f", abs($this->value['min'])); $this->query->add_where($this->options['group'], "ABS($field) <= %f", abs($this->value['max'])); } else { $this->query->add_where($this->options['group'], "ABS($field) <= %f OR ABS($field) >= %f", abs($this->value['min']), ($this->value['max'])); } } function op_simple($field) { $this->query->add_where($this->options['group'], "ABS($field) $this->operator %f", abs($this->value['value'])); } }
which is the same as 'views_handler_filter_float.inc'; its just ads "ABS()" to the query and the values.
I think a better approach would be to add an option to the form, and make it available for float and non float numeric values.
I can send a patch for views2 if you care.
Comments
Comment #1
dawehnerHuch? This is a bit confusing. In general you can solve all this if you enable ctools module and add the global: math field.
This allows you to apply some formulas to it, and based on this there is no problem to run abs() aor whatever you need.
Comment #2
enboig commentedI haven't tried ctools; I was asking for views to generate a query similar to:
Comment #3
dawehnerSo this is not really working.
It's cool if you could actually now what the people want.
Comment #4
merlinofchaos commentedUnfortunately, Views does not currently provide a feature to do this. Doing so would require a custom handler or query modification. Views is unlikely to provide a feature like this.
Comment #5
enboig commentedOk, I have coded a custom handler:
which is the same as 'views_handler_filter_float.inc'; its just ads "ABS()" to the query and the values.
I think a better approach would be to add an option to the form, and make it available for float and non float numeric values.
I can send a patch for views2 if you care.