5

I want to display CGridView component with all records as a link to its related Update page.

I want the functionality of edit button at the end of every row, applied to whole row.

If I click anywhere on a particular row, it will redirect me to its update screen respectively.

Is it possible in Yii's CGridView ?

Kai
  • 38,985
  • 14
  • 88
  • 103
Darshit Gajjar
  • 746
  • 4
  • 13
  • 26

3 Answers3

27

CGridView

'columns'=>array(
'id',
//'full_name',
//'username',
array(
        'name'  => 'full_name',
        'value' => 'CHtml::link($data->full_name, Yii::app()
 ->createUrl("user/view",array("id"=>$data->primaryKey)))',
        'type'  => 'raw',
    ),
array(
        'name'  => 'username',
        'value' => 'CHtml::link($data->username,Yii::app()->createUrl("user/view",array("id"=>$data->primaryKey)))',
        'type'  => 'raw',
    ),
'email',

To make whole row an link try this...

<?php $this->widget('zii.widgets.grid.CGridView', array(
...
'htmlOptions'=>array('style'=>'cursor: pointer;'),
'selectionChanged'=>"function(id){window.location='" . Yii::app()->urlManager->createUrl('controller/action', array('id'=>'')) . "' + $.fn.yiiGridView.getSelection(id);}",
...
)); ?>
Darshit Gajjar
  • 746
  • 4
  • 13
  • 26
Rajat Singhal
  • 11,234
  • 5
  • 38
  • 56
  • thanks for the reply, but it's not what I meant. In this solution, I am getting row **values** as link. while I want whole row to get link to its related view. If you can help with that :) – Darshit Gajjar Jan 04 '12 at 10:52
  • hey there is one more issue with selection on Grid row when I use **view** and not the **table** this -> **$.fn.yiiGridView.getSelection(id);** return nothing. What should i do – Darshit Gajjar Jan 10 '12 at 13:43
  • 1
    after a long gap, I found another scenario.. "Do I get any cell value of the row, when I click on it" ?? – Darshit Gajjar May 01 '12 at 12:53
2

Implement this:

'selectionChanged'=>"function(id){window.location='" .  Yii::app()->urlManager->createUrl('servers/view', array('id'=>$model->id)) . "' + $.fn.yiiGridView.getSelection(id);}",
Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
aqureshi
  • 61
  • 7
1

Put your code in admin grid view array(

                    'class'=>'CButtonColumn',
                    'header'=>'Action',
                    'htmlOptions'=>array('width'=>'75px'),
                    'template'=>'{Edit} {Delete}',
                    'buttons'=>array
                        (
                            'Edit' => array
                            (
                                'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',
                                'url'=>'Yii::app()->createUrl(\'vendor/artist/update\', array(\'id\'=>$data["id"],\'vid\'=>'.$vid.'))',
                                'options' => array('class' => 'editevent'),
                            ),

                            'Delete' => array
                            (
                                'imageUrl' => Yii::app()->request->baseUrl . '/images/delete.png',
                                'url'=>'Yii::app()->createUrl(\'vendor/artist/artistdelete\', array(\'id\'=>$data["id"],\'vid\'=>'.$vid.'))',
                                'options' => array('class' => 'status1'),
                            ),




                        ),
            ),
Ankit Modi
  • 11
  • 3