Admin View: How To Set A Default Search Criteria ?

In my model i’ve a ‘isActive’ Status (true/false, 0/1)

In the _search i’ve a dropdown combo for true/false with empty => ‘all’

In the CGridView i’ve the field declares as

array ( 

		        'name'=> 'isActive',

		        'value'=> 'Helper::booleanFormatter($data->isActive, "active","disabled")',

		        'filter' => array("1" => 'active', "0" => 'disabled);


where …

 public static function booleanFormatter($value, $true, $false) {

        return ( $value ? Yii::t('general', $true) : Yii::t('general', $false) )  ;


I need the the first time user view ‘/admin’, user see only active records. I need a default filter to ‘isActive=1’, but obviously, if user change it, the filter must be what the user want…

How to ?

You just need to set the isActive attribute to the desired value before rendering the view.

Yes ! :)

In the ItemController I added an else …




            $model->isActive = 1;   // default to '1'

Right before rendering the admin view, after assigning the attributes coming from the request, set the value you want to be fixed:

$model->active = 1;

100% working, thanks rodrigo !