Filter Cgridview On Simple Array

Goodafternoon,

I have a User model which can contain a password (when registered), but it is not required.

In my admin GridView I want an oversight in the users registered and the one who aren’t.

In my admin view I have:


array(	'header'=>'Registrered',

			'value' => '(!empty($data->password) ? "yes" : "no")',

			'filter'=> array('yes' => 'yes', 'no' => 'no')

		),

But this doesn’t do anything.

Normally I use CHtml::listData with a ::model()->findAll to create a dropdown filter,

but now I don’t know what I have to insert and can’t find the answer on the internet.

My Question:

I want a dropdown menu which can search for 0 and 1 (or yes and no) as the filter of my Registered column.

I hope someone can help me with this one.

Thank you in advance!

you should set name attribute of your column and add some logic in search method of model

example:

in model class do something like following




public $registered;


//remember to add this new attribute to your search rule

public function rule()

{

   return array(

         //other rules


         array('registered','safe', 'on'=>'search'),

     );

}


public function search()

{

        $criteria=new CDbCriteria;


       


        if($this->registered=='no')

            $criteria->addCondition('password is null');

        elseif($this->registered=='yes')

            $criteria->addCondition('password is not null');


         //your other search criteria

        


         return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

}




and in your gridview




array(  

                'name'=>'registered',

                'header'=>'Registrered',

                'value' => '(!empty($data->password) ? "yes" : "no")',

                'filter'=> array('yes' => 'yes', 'no' => 'no')

     ),