From f68d685faa2dfb8665ab22119ed81c2222fa8cc2 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 5 Jan 2014 13:18:18 -0500 Subject: [PATCH] Filtering fix When filtering you can not use the alias for WHERE #66 Convert columns as raw if they contain a parenthesis --- src/Bllim/Datatables/Datatables.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Bllim/Datatables/Datatables.php b/src/Bllim/Datatables/Datatables.php index 95fb69ce..fa3d15d7 100644 --- a/src/Bllim/Datatables/Datatables.php +++ b/src/Bllim/Datatables/Datatables.php @@ -7,7 +7,7 @@ * * @package Laravel * @category Bundle -* @version 1.3.1 +* @version 1.3.3 * @author Bilal Gultekin */ @@ -345,7 +345,7 @@ private function ordering() if(!is_null(Input::get('iSortCol_0'))) { - $columns = $this->cleanColumns( $this->last_columns ); + $columns = $this->clean_columns( $this->last_columns ); for ( $i=0, $c=intval(Input::get('iSortingCols')); $i<$c ; $i++ ) { @@ -360,15 +360,16 @@ private function ordering() } /** * @param array $cols + * @param bool $use_alias weather to get the column/function or the alias * @return array */ - private function cleanColumns( $cols ) + private function clean_columns( $cols, $use_alias = true) { $return = array(); foreach ( $cols as $i=> $col ) { preg_match('#^(.*?)\s+as\s+(\S*?)$#si',$col,$matches); - $return[$i] = empty($matches) ? $col : $matches[2]; + $return[$i] = empty($matches) ? $col : $matches[$use_alias?2:1]; } return $return; @@ -382,7 +383,7 @@ private function cleanColumns( $cols ) private function filtering() { - $columns = $this->cleanColumns( $this->columns ); + $columns = $this->clean_columns( $this->columns, false ); if (Input::get('sSearch','') != '') { @@ -448,7 +449,8 @@ private function filtering() $column = $db_prefix . $columns[$i]; $this->query->where(DB::raw('LOWER('.$column.')'),'LIKE', $keyword); } else { - $this->query->where($columns[$i], 'LIKE', $keyword); + $col = strstr($columns[$i],'(')?DB::raw($columns[$i]):$columns[$i]; + $this->query->where($col], 'LIKE', $keyword); } } }