Yii CGridView and dropdown filter
- by Dmitriy Gunchenko
I created dropdown filter, it's display, but don't worked right. As I anderstand trouble in search() method
view:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter' => $model,
'columns'=>array(
array(
'name' => 'client_id',
'filter' => CHtml::listData(Client::model()->findAll(), 'client_id', 'name'),
'value'=>'$data->client->name'
),
'task'
)
));
I have to tables, and they relations are shown down
model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'client' => array(self::BELONGS_TO, 'Client', 'client_id'),
);
}
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('client');
$criteria->compare('task_id',$this->task_id);
$criteria->compare('client_id',$this->client_id);
$criteria->compare('name',$this->client->name);
$criteria->compare('task',$this->task,true);
$criteria->compare('start_date',$this->start_date,true);
$criteria->compare('end_date',$this->end_date,true);
$criteria->compare('complete',$this->complete);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}