Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Cgridview filter relation improvement #2007

n3okill opened this Issue · 1 comment

2 participants


Describe the problem feature solves clearly. Explain why you need this and what is it exactly.

When we work with a cgridview where model's have relations and we need to display data from that relations, in most of the cases we need to filter and is really annoying to create new model variables and label's and set them in search().

Suggest on how it should be implemented if you have an idea.

I suggest a litle tweak in the framework/zii/widgets/grid/CDataColumn.php -> renderFilterCellContent() for the filter to handle the relation fields.

With that tweak we can use the filter's like this:

In controller

$model = new model('search');
$model->relationName = new relationModel('search');


    $model->relationName->attributes = $_GET['RelationModel'];

##In model

public function search() {
    $criteria = new CDbCriteria;

    $criteria->with = array('relationName');
    $criteria->together = true;

    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,

##In gridView

    $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $model->search(),
        'filter' => $model,
        'columns' => array(

Will open a pull request once doc block has been added using the guidelines outlined here -


which relation type this tweak will work ?. i had trying with has_many relationship . but error

"Trying to get property of non-object"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.