CGridView with smart filters

Hi:

I’m using Cgridview, and I can use filters with dropdowns taking values from a recordset or wherever.

But … is there a way to create a filter in which user can select (for example) ">6", referring to filter rows with that column values greater than 6 ?

In same way , less than, greater or equal than … …

Thank you

As you know, you can give an array of ‘value’=>‘text’ pairs as the filter. And in ‘value’, you may include the comparison operators.




$filter_array = array(

    '1' => 'One',

    '2' => 'Two',

    '<10' => 'Less than ten',

    '>=10' => 'Ten or more',

);

...

array(

    'name' => 'some_count',

    'filter' => $filter_array,

)



softark … yes, I knew it … but I want any value … i mean, I want the user to put anything he wants … <5 , <10, <64, <154 … anything … not fixed values

I see.

So you want a dropdownlist filter that can accept on-the-fly entries by the user?

Um, I don’t know what to do with it.

Well … a dropdown would have just fixed values , what I want is a input text box, and parse what user enters with a function to give my results to the grid

I’m not sure if I get you right …

The default inline textbox filter should work just as you want out of the box, if your search() method in the model can handle it right.




// in view

$this->widget('zii.widgets.grid.CGridView', array(

	'id' => 'some-grid',

	'dataProvider' => $model->search(),

	'filter' => $model,

	'columns' => array(

		array(

			'name' => 'some_count',

			// 'filter' => $some_filter,

		),

		...


// in search() method in model

		...

		$criteria->compare('some_count',$this->some_count);

		...