Difference between #4 and #8 of
Using filters with CGridView and CArrayDataProvider

Changes

Title unchanged

Using filters with CGridView and CArrayDataProvider

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

CGridview, CArrayDataProvider, filters, filter

Content changed

[...]
*/
public function filter(array $data)
{
foreach ($data AS $rowIndex => $row) {
foreach ($this->filters AS $key => $searchValue) {
if (!
emptyis_null($searchValue) AND $searchValue !== '') {
$compareValue = null;
[...]
```

(By @KonApaz)
 
If you want to apply full comparisons (>, <, >=, <=, =) use this
 
 
 
```php 
if (substr($searchValue, 0, 2) == '<=') {
 
    if ($compareValue > substr($searchValue, 2)) {
 
        unset($data[$rowIndex]);
 
    }
 
} else if (substr($searchValue, 0, 2) == '>=') {
 
    if ($compareValue < substr($searchValue, 2)) {
 
        unset($data[$rowIndex]);
 
    }
 
} else if ($searchValue[0] == '<') {
 
    if ($compareValue >= substr($searchValue, 1)) {
 
        unset($data[$rowIndex]);
 
    }
 
} else if ($searchValue[0] == '>') {
 
    if ($compareValue <= substr($searchValue, 1)) {
 
        unset($data[$rowIndex]);
 
    }
 
} else if (stripos($compareValue, $searchValue) === false) {
 
    unset($data[$rowIndex]);
 
}
 
```
 
 
 
Controller
----------
[...]
'filter'=>$filtersForm,
));
```

 
19 0
29 followers
Viewed: 93 956 times
Version: 1.1
Category: How-tos
Written by: marcovtwout
Last updated by: yugene
Created on: Sep 12, 2011
Last updated: 11 years ago
Update Article

Revisions

View all history