Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix search by columns #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions application/libraries/Datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function or_where($key_condition, $val = NULL, $backtick_protect = TRUE)
$this->ci->db->or_where($key_condition, $val, $backtick_protect);
return $this;
}

/**
* Generates the WHERE IN portion of the query
*
Expand Down Expand Up @@ -324,13 +324,27 @@ private function get_filtering()
$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' && !array_key_exists($mColArray[$i]['data'], $this->add_columns))
if($this->check_cType())
for($i = 0; $i < count($mColArray); $i++){
if(!empty($search['value'])){
$sSearch = $this->ci->db->escape_like_str(trim($search['value']));
if ($mColArray[$i]['searchable'] == 'true' && !array_key_exists($mColArray[$i]['data'], $this->add_columns)){
if($this->check_cType()){
$sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' OR ";
else
}else{
$sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $sSearch . "%' OR ";
}
}
}

if (!empty($mColArray[$i]['search']['value'])){
$cSearch = $this->ci->db->escape_like_str(trim($mColArray[$i]['search']['value']));
if($this->check_cType()){
$sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $cSearch . "%' OR ";
}else{
$sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $cSearch . "%' OR ";
}
}
}


$sWhere = substr_replace($sWhere, '', -3);
Expand Down Expand Up @@ -431,7 +445,7 @@ private function get_total_results($filtering = FALSE)

foreach($this->or_where as $val)
$this->ci->db->or_where($val[0], $val[1], $val[2]);

foreach($this->where_in as $val)
$this->ci->db->where_in($val[0], $val[1]);

Expand Down Expand Up @@ -467,7 +481,7 @@ private function get_total_results($filtering = FALSE)
private function exec_replace($custom_val, $row_data)
{
$replace_string = '';

// Go through our array backwards, else $1 (foo) will replace $11, $12 etc with foo1, foo2 etc
$custom_val['replacement'] = array_reverse($custom_val['replacement'], true);

Expand Down Expand Up @@ -629,7 +643,7 @@ private function jsonify($result = FALSE)
return '{' . join(',', $json) . '}';
}
}

/**
* returns the sql statement of the last query run
* @return type
Expand Down