Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display rows of CGridView as a link

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 ?

like image 781
Darshit Gajjar Avatar asked Jan 03 '12 13:01

Darshit Gajjar


3 Answers

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);}",
...
)); ?>
like image 106
Rajat Singhal Avatar answered Oct 02 '22 01:10

Rajat Singhal


Implement this:

'selectionChanged'=>"function(id){window.location='" .  Yii::app()->urlManager->createUrl('servers/view', array('id'=>$model->id)) . "' + $.fn.yiiGridView.getSelection(id);}",
like image 24
aqureshi Avatar answered Oct 02 '22 00:10

aqureshi


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




                        ),
            ),
like image 40
Ankit Modi Avatar answered Oct 02 '22 01:10

Ankit Modi