Skip to content

Commit f68d685

Browse files
committed
Filtering fix
When filtering you can not use the alias for WHERE bgultekin#66 Convert columns as raw if they contain a parenthesis
1 parent aed14a6 commit f68d685

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Bllim/Datatables/Datatables.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @package Laravel
99
* @category Bundle
10-
* @version 1.3.1
10+
* @version 1.3.3
1111
* @author Bilal Gultekin <bilal@bilal.im>
1212
*/
1313

@@ -345,7 +345,7 @@ private function ordering()
345345

346346
if(!is_null(Input::get('iSortCol_0')))
347347
{
348-
$columns = $this->cleanColumns( $this->last_columns );
348+
$columns = $this->clean_columns( $this->last_columns );
349349

350350
for ( $i=0, $c=intval(Input::get('iSortingCols')); $i<$c ; $i++ )
351351
{
@@ -360,15 +360,16 @@ private function ordering()
360360
}
361361
/**
362362
* @param array $cols
363+
* @param bool $use_alias weather to get the column/function or the alias
363364
* @return array
364365
*/
365-
private function cleanColumns( $cols )
366+
private function clean_columns( $cols, $use_alias = true)
366367
{
367368
$return = array();
368369
foreach ( $cols as $i=> $col )
369370
{
370371
preg_match('#^(.*?)\s+as\s+(\S*?)$#si',$col,$matches);
371-
$return[$i] = empty($matches) ? $col : $matches[2];
372+
$return[$i] = empty($matches) ? $col : $matches[$use_alias?2:1];
372373
}
373374

374375
return $return;
@@ -382,7 +383,7 @@ private function cleanColumns( $cols )
382383

383384
private function filtering()
384385
{
385-
$columns = $this->cleanColumns( $this->columns );
386+
$columns = $this->clean_columns( $this->columns, false );
386387

387388
if (Input::get('sSearch','') != '')
388389
{
@@ -448,7 +449,8 @@ private function filtering()
448449
$column = $db_prefix . $columns[$i];
449450
$this->query->where(DB::raw('LOWER('.$column.')'),'LIKE', $keyword);
450451
} else {
451-
$this->query->where($columns[$i], 'LIKE', $keyword);
452+
$col = strstr($columns[$i],'(')?DB::raw($columns[$i]):$columns[$i];
453+
$this->query->where($col], 'LIKE', $keyword);
452454
}
453455
}
454456
}

0 commit comments

Comments
 (0)