0
votes

I'm currently setting up a gridview where each result of a field in one table will need to become a header

Unfortunatly I can't seem to find a way that will set the values to be the header while also allowing a value in another table

For example, I need to have every result in the name field be the header for my cgridview

enter image description here Then every result that links up to the header for the value to also appear as the value for this header

enter image description here

My guess is that somehow I would add the results to a dataprovider, loop round the dataprovider for results to fill the columns and use this function as the result for the gridview but the page breaks if I do not strictly define columns

The issue I'm having is that the column is still displaying as the HEADER1 rather than the data, and the data is simply the data I'm pulling

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

and my view

array(
            'header' => $data['Header1'],
            'name' => 'Header1',
            'type' => 'raw',
            'value' => $data['Question6'],
        ),

and the result is simply inputting what I want as the header into the value, and the AS identifier as the header.

enter image description here

1

1 Answers

1
votes

You can use header property of the columns

array('name'=>'yoir_column_name',
  'header'=> '$your_value_from_db_for_header',
 ),

should be somethings like this

$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',
        ),