Closed leocaseiro closed 10 years ago
Are you getting any errors? Can you provide example code either in here or via pastebin?
I was following the same idea as the Issue #7.
So, I changed the method getWhereConditions() and now it's working. I swapped OR to AND, and also I'm using 'sSearch_'.$x instead of only 'sSearch'.
foreach($fields as $x => $column){
// only create conditions on bSearchable fields
if( isset($this->controller->request->query['bSearchable_'.$x]) && $this->controller->request->query['bSearchable_'.$x] == 'true' && $this->controller->request->query['sSearch_'.$x] != '' ){
list($table, $field) = explode('.', $column);
// attempt using definitions in $model->validate to build intelligent conditions
if( $this->conditionsByValidate == 1 && array_key_exists($column,$this->model->validate) ){
if( !empty($this->controller->paginate['contain']) ){
if(array_key_exists($table, $this->controller->paginate['contain']) && in_array($field, $this->controller->paginate['contain'][$table]['fields'])){
$conditions[$table]['conditions'][] = $this->conditionByDataType($column);
}
}
else{
$conditions['AND'][] = $this->conditionByDataType($column);
}
}
else{
if( !empty($this->controller->paginate['contain']) ){
if(array_key_exists($table, $this->controller->paginate['contain']) && in_array($field, $this->controller->paginate['contain'][$table]['fields'])){
$conditions[$table]['conditions'][] = $column.' LIKE "%'.$this->controller->request->query['sSearch_'.$x].'%"';
}
}
else{
$conditions['AND'][] = array(
$column.' LIKE' => '%'.$this->controller->request->query['sSearch_'.$x].'%'
);
}
}
}
}
However, I'd like to concat the MySQL Query using both filters. Like:
SELECT * FROM table WHERE (field_1 = 'sSearch' OR field_2 = 'sSearch_' ...) AND field_1 = 'sSearch_1' AND field_2 = 'sSearch_2'
I'm begginer on CakePHP, so do you know where can I find it on documentation of ORM? If do you prefer, I can commit for you in my fork and you can see exactly what I've done to the script works...
I've just realized that is so much easier that I was expecting.
I just added my code in your code and it's worked.
Many thanks anyway.
Ok, if it works it works.
I'm using in a Project and I'll need to implement the columnFilter plugin.
I tried using as default and didn't work.
I put the JS in my webroot and linked on my Layout and it's still not working.
I'm working on it. I'm studying your algorithm to see when should I put the filters to send from the URL json to the Model.
The Plugin is http://jquery-datatables-column-filter.googlecode.com/svn/trunk/default.html
I found out there are a new sSearch var for each column sSearch_1, sSearch_2, sSearch_3, etc...
So I need to add on the WHERE QUERY.