From 5d1511a87cb8e71d1f3e87115fe4a18df9bf1330 Mon Sep 17 00:00:00 2001 From: "Mr.Jack" Date: Sun, 26 Jul 2015 01:18:39 -0500 Subject: [PATCH] Adding Individual Column Filter --- application/libraries/Datatables.php | 65 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/application/libraries/Datatables.php b/application/libraries/Datatables.php index 0160b5c..8fc8860 100644 --- a/application/libraries/Datatables.php +++ b/application/libraries/Datatables.php @@ -300,32 +300,45 @@ private function get_ordering() */ private function get_filtering() { - - $mColArray = $this->ci->input->post('columns'); - - $sWhere = ''; - $search = $this->ci->input->post('search'); - $sSearch = $this->ci->db->escape_like_str(trim($search['value'])); - $columns = array_values(array_diff($this->columns, $this->unset_columns)); - - if($sSearch != '') - for($i = 0; $i < count($mColArray); $i++) - if($mColArray[$i]['searchable'] == 'true' ) - if($this->check_cType()) - $sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' OR "; - else - $sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $sSearch . "%' OR "; - - - $sWhere = substr_replace($sWhere, '', -3); - - if($sWhere != '') - $this->ci->db->where('(' . $sWhere . ')'); - - // TODO : sRangeSeparator - - foreach($this->filter as $val) - $this->ci->db->where($val[0], $val[1], $val[2]); + $mColArray = $this->ci->input->post('columns'); + $sWhere = ''; + $search = $this->ci->input->post('search'); + $sSearch = $this->ci->db->escape_like_str(trim($search['value'])); + $columns = array_values(array_diff($this->columns, $this->unset_columns)); + + if($sSearch != ''){ + for($i = 0; $i < count($mColArray); $i++){ + if($mColArray[$i]['searchable'] == 'true' ) + if($this->check_cType()) + $sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' OR "; + else + $sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $sSearch . "%' OR "; + } + $sWhere = substr_replace($sWhere, '', -3); + if($sWhere != '') + $this->ci->db->where('(' . $sWhere . ')'); + } + + $sWhere = ''; + for($i = 0; $i < count($mColArray); $i++){ + $sSearch = $this->ci->db->escape_like_str(trim($mColArray[$i]['search']['value'])); + if($mColArray[$i]['searchable'] == 'true' && !empty($sSearch) ) + if($this->check_cType()) + $sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' AND "; + else + $sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $sSearch . "%' AND "; + } + $sWhere = substr_replace($sWhere, '', -4); + + if($sWhere != '') + $this->ci->db->where('(' . $sWhere . ')'); + + // TODO : sRangeSeparator + + foreach($this->filter as $val) + $this->ci->db->where($val[0], $val[1], $val[2]); + + //echo $sWhere ; } /**