Would it be possible to activate an option in numeric filter so when you enter "20", the values shown are "20" and "-20"?

Comments

dawehner’s picture

Status: Active » Fixed

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.

enboig’s picture

I haven't tried ctools; I was asking for views to generate a query similar to:

SELECT * FROM ... WHERE abs(numeric_field) = %f
dawehner’s picture

Status: Fixed » Active

So this is not really working.

It's cool if you could actually now what the people want.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

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.

enboig’s picture

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.