我目前正在设置一个gridview,其中一个表中字段的每个结果都需要成为一个标题
不幸的是,我似乎无法找到一种方法将值设置为标题,同时还允许另一个表中的值
例如,我需要将name字段中的每个结果都作为我的cgridview
的标题我的猜测是,我会以某种方式将结果添加到数据提供者,循环数据提取器以获取结果以填充列并使用此函数作为gridview的结果但如果我没有严格定义列则分页
我遇到的问题是该列仍然显示为HEADER1而不是数据,而数据只是我拉的数据
public function exportSearch($event_id){
$query = "SELECT
u.prefix AS 'Title',
u.forename AS 'Forename',
u.surname AS 'Surname',
u.telephone AS 'Mobile Number',
u.email AS 'Email Address',
ea.checkin_status_id AS 'checked in',
u.update_time AS 'Register Date',
eg.name AS 'Event Group Registered',
e.name AS 'Session Registered',
u.bio AS 'User Information',
u.dob AS 'Date of Birth',
u.company AS 'Company',
u.company_role AS 'Company Role',
CONCAT(u2.forename, ' ', u2.surname) AS 'Guest of',
MAX(CASE WHEN uv.user_type_variables_id = 1 THEN uv.name ELSE NULL END) AS Header1,
MAX(CASE WHEN uv.user_type_variables_id = 1 THEN uv.value ELSE NULL END) AS Question1,
MAX(CASE WHEN uv.user_type_variables_id = 2 THEN uv.value ELSE NULL END) AS Question2,
MAX(CASE WHEN uv.user_type_variables_id = 3 THEN uv.value ELSE NULL END) AS Question3,
MAX(CASE WHEN uv.user_type_variables_id = 4 THEN uv.value ELSE NULL END) AS Question4,
MAX(CASE WHEN uv.user_type_variables_id = 5 THEN uv.value ELSE NULL END) AS Question5,
MAX(CASE WHEN uv.user_type_variables_id = 6 THEN uv.value ELSE NULL END) AS Question6
FROM tbl_event_attendees AS ea
LEFT JOIN tbl_user AS u ON ea.user_id = u.id
LEFT JOIN tbl_event AS e ON ea.event_id = e.id
LEFT JOIN tbl_event_groups AS eg on e.group_id = eg.id
LEFT JOIN tbl_user AS u2 ON ea.guest_of_user_id = u2.id
LEFT JOIN tbl_user_variables AS uv on u.id = uv.user_id
WHERE ea.event_id = {$event_id}
GROUP BY ea.id";
$count=Yii::app()->db->createCommand($query)->queryScalar();
return $sqlDataprovider = new CSqlDataProvider($query, array(
'totalItemCount'=>$count,
'sort'=>array(
'attributes'=>array(
)
),
'pagination'=>array(
'pageSize'=>$count, //Show all records
),
));
}
和我的观点
array(
'header' => $data['Header1'],
'name' => 'Header1',
'type' => 'raw',
'value' => $data['Question6'],
),
结果只是将我想要的标题输入到值中,并将AS标识符作为标题输入。
答案 0 :(得分:1)
您可以使用列的标题属性
array('name'=>'yoir_column_name',
'header'=> '$your_value_from_db_for_header',
),
应该是这样的事情
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'your_id',
'dataProvider'=>$dataProvider,
'columns'=>array(
'your_first_column' ,
'your_second_column',
array(
'header'=> $data['Header1'],
'value'=> '$data->Question6',
'name'=> 'Question6',
),