Create Drop Down Filter With Cactivedataprovider

I am having trouble creating a drop down filter in GridView using CActiveDataProvider. I want to have a drop down list as a filter in my view for status which is stored as an Integer in the database. In my controller I have




$dataProvider = new CActiveDataProvider('ClientTask', array(

			'criteria'=>array(

				'condition'=>'client_id=:cldtid AND active = 1',

				'order'=>'creation_date DESC',

				'params'=>array(':cldtid'=>$cl_det['id']),

				),

			'pagination'=>array(

				'pageSize'=>5,

				),

			));

		$this->render('notice', array(

			 'dataProvider'=>$dataProvider, ));



In my view I have




$this->widget('bootstrap.widgets.TbGridView', array(

    'type'=>'striped bordered condensed',

    'dataProvider'=>$dataProvider,

    'enablePagination'=>true,

    'summaryText'=>'Displaying {start}-{end} of {count} results.',

    'template' => "{summary}{items}{pager}",

    'columns'=>array(

        array('name'=>'id', 

        	'header'=>'Job #',

        	'value'=>'$data->id',

        	'htmlOptions'=>array('style'=>'width:10px;text-align:center;')),

        array('name'=>'creation_date',

        	'header'=>'Date Created',

        	'value'=>'Yii::app()->dateFormatter->format("d-M-y",$data->creation_date)',

        	'htmlOptions'=>array('style'=>'width:50px;text-align:center;')),

        array('name'=>'status', 

        	'header'=>'Status',

        	'value'=>'CHtml::encode($data->getActiveStatusText())',

        	'htmlOptions'=>array('style'=>'width:50px;text-align:center;')),

        array('name'=>'countcontractors',

            'header'=>'No. of Contractors',

            'value'=>array($this,'gridDataColumn'),

            'htmlOptions'=>array('style'=>'width:50px;text-align:center;'),

            ),

        array(

            'class'=>'bootstrap.widgets.TbButtonColumn',

            'header'=>'View Job',

            'template'=>'{view}',

            'htmlOptions'=>array('style'=>'width:20px;text-align:center;'),

        ),

    ),

));



In my model I have




class ClientTask extends CActiveRecord

{

/* STATUS_MANUAL - Client has uploaded a file and requires staff to enter contractors manually */


	const STATUS_CREATED=0;

	const STATUS_PROGRESS=1;

	const STATUS_READY=2;

	const STATUS_MANUAL=3;

	const STATUS_FINALISED=4;

	const STATUS_SENT=5;

	const STATUS_EMAILED=6;




	public function getActiveStatus()

	{

		return array(

			self::STATUS_CREATED=>'Job Created',

			self::STATUS_PROGRESS=>'Not Submitted',

			self::STATUS_READY=>'Submitted',

			self::STATUS_MANUAL=>'Manual Entry Required',

			self::STATUS_FINALISED=>'Compliance Check Completed',

			self::STATUS_SENT=>'Ready to send to Client',

			self::STATUS_EMAILED=>'File emailed to Client',

			);

	}




	public function getActiveStatusText () 

	{

		$activeStatus=$this->getActiveStatus();

		return isset($activeStatus[$this->status]) ? $activeStatus[$this->status] : "unkown status({$this->status})";

	}



I use these functions for my forms when users enter the data. I thought I could make use of these functions to create a drop down list in my view for status something along the lines of




'filter'=>$model->getActiveStatus(),



Obviously I cannot do this as I am using CActiveDataProvider however is there someway to make use of the model functions to create a drop down list. I have tried number of different ways however I would not have thought it would be that difficult as I use ‘filter’ in the last code snippet in other admin views when my dataProvider is $model->search().

Could someone point me in the right direction please.

bump

One final bump

Haven’t tested it but could you use the static model for your filter?





$this->widget('bootstrap.widgets.TbGridView', array(

    'type'=>'striped bordered condensed',

    'dataProvider'=>$dataProvider,

    'enablePagination'=>true,

	'filter' => ClientTask::model(), // NOTICE

    'summaryText'=>'Displaying {start}-{end} of {count} results.',

    'template' => "{summary}{items}{pager}",

    'columns'=>array(

        array('name'=>'id', 

			'header'=>'Job #',

			'value'=>'$data->id',

			'htmlOptions'=>array('style'=>'width:10px;text-align:center;')),

        array('name'=>'creation_date',

			'header'=>'Date Created',

			'value'=>'Yii::app()->dateFormatter->format("d-M-y",$data->creation_date)',

			'htmlOptions'=>array('style'=>'width:50px;text-align:center;')),

        array('name'=>'status', 

			'filter' => ClientTask::model()->getActiveStatus(),  // NOTICE

			'header'=>'Status',

			'value'=>'CHtml::encode($data->getActiveStatusText())',

			'htmlOptions'=>array('style'=>'width:50px;text-align:center;')),

        array('name'=>'countcontractors',

            'header'=>'No. of Contractors',

            'value'=>array($this,'gridDataColumn'),

            'htmlOptions'=>array('style'=>'width:50px;text-align:center;'),

            ),

        array(

            'class'=>'bootstrap.widgets.TbButtonColumn',

            'header'=>'View Job',

            'template'=>'{view}',

            'htmlOptions'=>array('style'=>'width:20px;text-align:center;'),

        ),

    ),

));