Skip to content

Commit

Permalink
fix filterColumn when using column search. fix #52
Browse files Browse the repository at this point in the history
  • Loading branch information
yajra committed May 19, 2015
1 parent 78f53c8 commit 5ce6680
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/yajra/Datatables/Engine/BaseEngine.php
Expand Up @@ -1071,13 +1071,30 @@ public function doColumnSearch(array $columns)
$column = $columns[$i]['name'];
$keyword = $this->setupKeyword($columns[$i]['search']['value']);

// wrap column possibly allow reserved words to be used as column
$column = $this->wrapColumn($column);
if ($this->isCaseInsensitive()) {
$this->query->whereRaw('LOWER(' . $column . ') LIKE ?', [Str::lower($keyword)]);
if (isset($this->filter_columns[$column])) {
extract($this->filter_columns[$column]);
if ( ! Str::contains(Str::lower($method), 'or')) {
$method = 'or' . ucfirst($method);
}

if (method_exists($this->getBuilder(), $method)
&& count($parameters) <= with(new \ReflectionMethod($this->getBuilder(), $method))->getNumberOfParameters()
) {
if (Str::contains(Str::lower($method), 'raw') or Str::contains(Str::lower($method), 'exists')) {
call_user_func_array(array($this->getBuilder(), $method), $this->parameterize($parameters));
} else {
call_user_func_array(array($this->getBuilder(), $method), $this->parameterize($column, $parameters));
}
}
} else {
$col = strstr($column, '(') ? $this->connection->raw($column) : $column;
$this->query->whereRaw($col . ' LIKE ?', [$keyword]);
// wrap column possibly allow reserved words to be used as column
$column = $this->wrapColumn($column);
if ($this->isCaseInsensitive()) {
$this->query->whereRaw('LOWER(' . $column . ') LIKE ?', [Str::lower($keyword)]);
} else {
$col = strstr($column, '(') ? $this->connection->raw($column) : $column;
$this->query->whereRaw($col . ' LIKE ?', [$keyword]);
}
}
}
}
Expand Down

0 comments on commit 5ce6680

Please sign in to comment.