Skip to content

Commit 03a1d9c

Browse files
committed
fix case insensitive filtering and remove trailing spaces
1 parent 0c21b70 commit 03a1d9c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/Bllim/Datatables/Datatables.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ private function clean_columns( $cols, $use_alias = true)
369369
foreach ( $cols as $i=> $col )
370370
{
371371
preg_match('#^(.*?)\s+as\s+(\S*?)$#si',$col,$matches);
372-
$return[$i] = empty($matches) ? $col : $matches[$use_alias?2:1];
372+
$return[$i] = empty($matches) ? $col : $matches[$use_alias?2:1];
373373
}
374374

375375
return $return;
@@ -384,7 +384,7 @@ private function clean_columns( $cols, $use_alias = true)
384384
private function filtering()
385385
{
386386
$columns = $this->clean_columns( $this->columns, false );
387-
387+
388388
if (Input::get('sSearch','') != '')
389389
{
390390
$copy_this = $this;
@@ -393,25 +393,25 @@ private function filtering()
393393
$this->query->where(function($query) use ($copy_this) {
394394

395395
$db_prefix = $copy_this->database_prefix();
396-
397-
396+
397+
398398

399399
for ($i=0,$c=count($copy_this->columns);$i<$c;$i++)
400400
{
401401
if (Input::get('bSearchable_'.$i) == "true")
402402
{
403403
$column = $copy_this->columns[$i];
404-
405-
if (stripos($column, ' AS ') !== false){
404+
405+
if (stripos($column, ' AS ') !== false){
406406
$column = substr($column, stripos($column, ' AS ')+4);
407407
}
408-
408+
409409
$keyword = '%'.Input::get('sSearch').'%';
410410

411411
if(Config::get('datatables.search.use_wildcards', false)) {
412412
$keyword = $copy_this->wildcard_like_string(Input::get('sSearch'));
413413
}
414-
414+
415415
// Check if the database driver is PostgreSQL
416416
// If it is, cast the current column to TEXT datatype
417417
$cast_begin = null;
@@ -420,10 +420,10 @@ private function filtering()
420420
$cast_begin = "CAST(";
421421
$cast_end = " as TEXT)";
422422
}
423-
423+
424424
$column = $db_prefix . $column;
425425
if(Config::get('datatables.search.case_insensitive', false)) {
426-
$query->orwhere(DB::raw('LOWER('.$cast_begin.$column.$cast_end.')'), 'LIKE', $keyword);
426+
$query->orwhere(DB::raw('LOWER('.$cast_begin.$column.$cast_end.')'), 'LIKE', strtolower($keyword));
427427
} else {
428428
$query->orwhere(DB::raw($cast_begin.$column.$cast_end), 'LIKE', $keyword);
429429
}
@@ -432,7 +432,7 @@ private function filtering()
432432
});
433433

434434
}
435-
435+
436436
$db_prefix = $this->database_prefix();
437437

438438
for ($i=0,$c=count($columns);$i<$c;$i++)
@@ -447,7 +447,7 @@ private function filtering()
447447

448448
if(Config::get('datatables.search.case_insensitive', false)) {
449449
$column = $db_prefix . $columns[$i];
450-
$this->query->where(DB::raw('LOWER('.$column.')'),'LIKE', $keyword);
450+
$this->query->where(DB::raw('LOWER('.$column.')'),'LIKE', strtolower($keyword));
451451
} else {
452452
$col = strstr($columns[$i],'(')?DB::raw($columns[$i]):$columns[$i];
453453
$this->query->where($col, 'LIKE', $keyword);

0 commit comments

Comments
 (0)