如何使用extraRowColumns访问groupgridview中的关系数据

时间:2016-08-27 18:15:01

标签: yii yii-extensions

数据库表:

project_master (id, project_name)  
task_master (id, task_name, project_id)

TaskMaster模型中的关系:

TaskMaster.php

class TaskMaster extends CActiveRecord
{
    /**
     * @return array relational rules.
     */
    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(
            'ProjectsRpl' => array(self::BELONGS_TO, 'Projects', 'project_id'),
        );
    }
}

关注GroupGridView查看文件:

Task.php

$this->widget('ext.groupgridview.GroupGridView', array(
      'id' => 'Customer-grid',
      'dataProvider' => $modelCustomer->searchCustomer(),
      //'mergeColumns' => 'project_id',
      'extraRowColumns' => array('ProjectsRpl.project_name'),
      'extraRowPos' => 'above',
      'afterAjaxUpdate' => 'function(){}',
      'columns'=>$columns,
));

GroupGridView reference site

获得以下错误:

  

CException:找不到列或属性“ProjectsRpl.project_name”!

1 个答案:

答案 0 :(得分:0)

Task.php 文件中只有一处更改。

$this->widget('ext.groupgridview.GroupGridView', array(
      'id' => 'Customer-grid',
      'dataProvider' => $model->search(),
      //'mergeColumns' => 'project_id',
      'extraRowColumns' => array('project_id'),
      'extraRowPos' => 'above',
      'extraRowExpression' => '"<b style=\"color: black\">".$data->ProjectsRpl->project_name."</b>"',
      'afterAjaxUpdate' => 'function(){}',
      'ajaxUrl' => Yii::app()->createUrl('customer/index'),
      'ajaxUpdate' => true,
      'enablePagination' => true,
      "summaryText" => true,
      'enableSorting' => FALSE,
      'columns'=>$columns,
));