Skip to content

Commit 4e5618f

Browse files
authored
Merge pull request #2079 from apreiml/9.0
[9.0] Consider black listed columns on column search.
2 parents 324aeb3 + 3370cd6 commit 4e5618f

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/CollectionDataTable.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,38 @@ public function columnSearch()
9393
{
9494
$columns = $this->request->get('columns', []);
9595
for ($i = 0, $c = count($columns); $i < $c; $i++) {
96-
if ($this->request->isColumnSearchable($i)) {
97-
$this->isFilterApplied = true;
96+
$column = $this->getColumnName($i);
9897

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

103-
$this->collection = $this->collection->filter(
104-
function ($row) use ($column, $keyword, $regex) {
105-
$data = $this->serialize($row);
102+
$this->isFilterApplied = true;
106103

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

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

114-
return strpos(Str::lower($value), Str::lower($keyword)) !== false;
115-
}
111+
$value = Arr::get($data, $column);
116112

113+
if ($this->config->isCaseInsensitive()) {
117114
if ($regex) {
118-
return preg_match('/' . $keyword . '/', $value) == 1;
115+
return preg_match('/' . $keyword . '/i', $value) == 1;
119116
}
120117

121-
return strpos($value, $keyword) !== false;
118+
return strpos(Str::lower($value), Str::lower($keyword)) !== false;
122119
}
123-
);
124-
}
120+
121+
if ($regex) {
122+
return preg_match('/' . $keyword . '/', $value) == 1;
123+
}
124+
125+
return strpos($value, $keyword) !== false;
126+
}
127+
);
125128
}
126129
}
127130

src/QueryDataTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ public function columnSearch()
278278
$columns = $this->request->columns();
279279

280280
foreach ($columns as $index => $column) {
281-
if (! $this->request->isColumnSearchable($index)) {
281+
$column = $this->getColumnName($index);
282+
283+
if (! $this->request->isColumnSearchable($index) || $this->isBlacklisted($column)) {
282284
continue;
283285
}
284286

285-
$column = $this->getColumnName($index);
286-
287287
if ($this->hasFilterColumn($column)) {
288288
$keyword = $this->getColumnSearchKeyword($index, $raw = true);
289289
$this->applyFilterColumn($this->getBaseQueryBuilder(), $column, $keyword);

0 commit comments

Comments
 (0)