Hi there. Actually i have an index.php page on which i want to show a TbGridView. Gridview is working with filter well. But some attributes, that are assigned to columns of gridview, are relational. Means getting data using relations. My index.php file is like
$this->widget('bootstrap.widgets.TbGridView', array(
'filter'=>$model,
'type' => 'bordered',
'dataProvider' => $model->search(),
'template' => "{items}",
'columns' => array(
array('name' => 'code', 'htmlOptions' => array("style" => "text-align:center"), 'headerHtmlOptions' => array("style" => "text-align:center"),),
array('name' => 'name', 'htmlOptions' => array("style" => "text-align:center"), 'headerHtmlOptions' => array("style" => "text-align:center")),
//array('header' => "Teacher", 'value' => '$data->teacher->getFullName()', 'htmlOptions' => array("style" => "text-align:center"), 'headerHtmlOptions' => array("style" => "text-align:center")),
array('header' => "Status", 'name' => "status", 'value' => 'ucwords($data->status->key)', 'htmlOptions' => array("style" => "text-align:center"), 'headerHtmlOptions' => array("style" => "text-align:center")),
array('header' => 'Class', 'name' => 'classGrade', 'value' => 'ucwords($data->classGrade->standard_name)', 'htmlOptions' => array('style' => 'text-align:center'), 'headerHtmlOptions' => array('style' => 'text-align:center')),
array('name' => 'fee', 'headerHtmlOptions' => array("style" => "text-align:center"), 'htmlOptions' => array("style" => "text-align:center")),
//array('header' => "Class/Grade", 'value' => '$data->classGrade->standard_name', 'htmlOptions' => array("style" => "text-align:center"), 'headerHtmlOptions' => array("style" => "text-align:center")),
array(
'template' => '{update}{delete}',
'htmlOptions' => array('nowrap' => 'nowrap'),
'class' => 'bootstrap.widgets.TbButtonColumn',
)
),
));
My action index is like.
public function actionIndex() {
$model=new Course('search');
$model->unsetAttributes();
$dataProvider = new CActiveDataProvider('Course');
if(isset($_GET['Course']))
$model->attributes=$_GET['Course'];
$this->render('index', array(
'dataProvider' => $dataProvider,
'model'=>$model,
));
My search function in model is like
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('code',$this->code,true);
$criteria->compare('teacher_id',$this->teacher_id,true);
$criteria->compare('status_id',$this->status_id,true);
$criteria->compare('fee',$this->fee,true);
$criteria->compare('class_grade_id',$this->class_grade_id,true);
$criteria->compare('credit_Hour',$this->credit_Hour,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
Now the problem is that gridview does not search on that attributes that are get using relation like "$data->status->key". I can change change the action index and write my own query with join statement but i want to do it in my search method. Is there any way to do that my search is enabled for relational attributes?