What I would like to do is to allow users to search by status, but I want them to be able to use dropdown menu with 2 options to select ( Active, Not Active ). Of course dropdown will replace this input field where you have to type values by default.
GridVew are made of “datacolomns”. Datacolumn has a ‘filter’ attribute that can either be a boolean (to suppress the filter) or an array of list of values.
If you give it a list of value, it will build a drop down selector on it.
'name'=>'status', //name of the column present in table
'filter'=>array('0'=>'active', '1'=>'not active'), //key=>value pair where 0 & 1 are the values present in table column.
),
add the above code in your admin.php file
For more precise understanding check the below code:
'id'=>'comments-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'intId',
array(
'name'=>'status', //name of the column present in table
'filter'=>array('0'=>'active', '1'=>'not active'), //key=>value pair where 0 & 1 are the values present in table column.
), //adding filter dropdown
array(
'class'=>'CButtonColumn',
),
),