Skip to content

Commit

Permalink
Merge pull request #2079 from apreiml/9.0
Browse files Browse the repository at this point in the history
[9.0] Consider black listed columns on column search.
  • Loading branch information
yajra authored May 9, 2019
2 parents 324aeb3 + 3370cd6 commit 4e5618f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
41 changes: 22 additions & 19 deletions src/CollectionDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,38 @@ public function columnSearch()
{
$columns = $this->request->get('columns', []);
for ($i = 0, $c = count($columns); $i < $c; $i++) {
if ($this->request->isColumnSearchable($i)) {
$this->isFilterApplied = true;
$column = $this->getColumnName($i);

$regex = $this->request->isRegex($i);
$column = $this->getColumnName($i);
$keyword = $this->request->columnKeyword($i);
if (! $this->request->isColumnSearchable($i) || $this->isBlacklisted($column)) {
continue;
}

$this->collection = $this->collection->filter(
function ($row) use ($column, $keyword, $regex) {
$data = $this->serialize($row);
$this->isFilterApplied = true;

$value = Arr::get($data, $column);
$regex = $this->request->isRegex($i);
$keyword = $this->request->columnKeyword($i);

if ($this->config->isCaseInsensitive()) {
if ($regex) {
return preg_match('/' . $keyword . '/i', $value) == 1;
}
$this->collection = $this->collection->filter(
function ($row) use ($column, $keyword, $regex) {
$data = $this->serialize($row);

return strpos(Str::lower($value), Str::lower($keyword)) !== false;
}
$value = Arr::get($data, $column);

if ($this->config->isCaseInsensitive()) {
if ($regex) {
return preg_match('/' . $keyword . '/', $value) == 1;
return preg_match('/' . $keyword . '/i', $value) == 1;
}

return strpos($value, $keyword) !== false;
return strpos(Str::lower($value), Str::lower($keyword)) !== false;
}
);
}

if ($regex) {
return preg_match('/' . $keyword . '/', $value) == 1;
}

return strpos($value, $keyword) !== false;
}
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/QueryDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ public function columnSearch()
$columns = $this->request->columns();

foreach ($columns as $index => $column) {
if (! $this->request->isColumnSearchable($index)) {
$column = $this->getColumnName($index);

if (! $this->request->isColumnSearchable($index) || $this->isBlacklisted($column)) {
continue;
}

$column = $this->getColumnName($index);

if ($this->hasFilterColumn($column)) {
$keyword = $this->getColumnSearchKeyword($index, $raw = true);
$this->applyFilterColumn($this->getBaseQueryBuilder(), $column, $keyword);
Expand Down

0 comments on commit 4e5618f

Please sign in to comment.