Between Value on Search Field - CGridView

how can i set between value on search field in CGridView???

ex : if i want to search age between 25 until 50 ( >25 & <50 )


I think it’s not possible to do this in the search form, maybe you can examine the input parameter in the model’s search() method. Like if you give the search parameter 10<x<50 you can set an interval with addBetweenCondition().

This is just a theory, haven’t tried it!

yeah… I got szako’s idea…

so basically in the model search() method we must put some validation for special keyword

let’s say we use double dot (…) as the special symbol for BETWEEN so the user may input like this


then in the search() we might put like this then right?

$arr = explode("..",$this->data);

$lower = $arr[0];

$higher = $arr[1];


$criteria->addBetweenCondition('column_name', $lower, $higher);

hope this help!

thanks for reply…

i have success create this function after i combine the solution from szako and junxiong…

You can do even with 2 textboxes:

In the CDataColumn you have to set the filter option:

'filter'=>CHtml::activeTextField($model, 'minAge').'<br>'.CHtml::activeTextField($model, 'maxAge'),

In the model you have to:

Create 2 property for receive the imputs:

public $minAge;

public $maxAge;

Add to the safe attributу for search;

Modify the search function:

$criteria->addBetweenCondition('column_name', $this->minAge, $this->maxAge);

The nice stuff of this approach is that you have not to force your user to use some strange syntax. You can also style a bit better youк texbox, for example:

'filter'=>CHtml::activeTextField($model, 'minAge', array('style="width:45%"')).

 '<span style="display:inline-block; width:10%"><age<'.

CHtml::activeTextField($model, 'maxAge', array('style="width:45%"')),

yeah, two boxes is cooler! :)

please, hepl me.

I have written code as discribed by zaccaria, but grid show result are empty, no matter what i enter into textboxes