Yii CGridView and dropdown filter

Posted by Dmitriy Gunchenko on Stack Overflow See other posts from Stack Overflow or by Dmitriy Gunchenko
Published on 2012-10-07T15:34:15Z Indexed on 2012/10/07 15:37 UTC
Read the original article Hit count: 239

Filed under:
|

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,
    ));
}

© Stack Overflow or respective owner

Related posts about filter

Related posts about yii