Hope someone can help me:
I have a table called ‘reference’ with a field called ‘article_type’, which i want to attach a dropdown filter to because it has only two possible values, ‘research’ or ‘review’.
here is the relevant model with ‘$criteria->compare(‘article_type’,$this->article_type);’:
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('gdoc_ref_id',$this->gdoc_ref_id);
$criteria->compare('date',$this->date);
$criteria->compare('abstract',$this->abstract,true);
$criteria->compare('summary',$this->summary,true);
$criteria->compare('full_ref',$this->full_ref,true);
$criteria->compare('toxin_type',$this->toxin_type,true);
$criteria->compare('article_type',$this->article_type);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination' => array( 'pageSize' => 10 ),
));
}
AND HERE IS MY VIEW (see ‘test dropdown’ in the column array):
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'reference-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
// these are the visible columns in the gridview table and their order
'columns'=>array(
array(
'name' => 'gdoc_ref_id',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->gdoc_ref_id), Yii::app()->request->baseUrl . "/pdf/" .
CHtml::encode($data->gdoc_ref_id). ".pdf", array("target"=>"_blank"))',
),
'date',
'toxin_type',
'abstract',
[b]//test dropdown[/b]
NOTE: THIS FILTERS FINE IF i USE ‘NAME’ AND REMOVE FILTER, SO I AM ASSUMING MY MODEL IS FINE BUT JUST NOT ASSOCIATING THE DROPDOWN BOX WITH THE MODEL ?
array(
//'name'=>'article_type', // this filters fine when i use it to replace 'filter'
'value'=>'$data->article_type',
'filter' => CHtml::dropDownList(
'article_type',
$model->article_type,
array('review' => 'Review',
'research' => 'Research',),
array('empty' => '(Select)'))
),
array(
'class'=>'CButtonColumn',
'template'=>'{view}',
'header' => 'Details',
'buttons'=>array(
'view'=>array(
'visible'=>'true',
),
),
),
),
));