Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make row in gridview clickable?

I am very new to yii2. I have created a gridview using CRUD Generator. I want to make the gridview's rows to be clickable like when we click on view. It should navigate to the view page for that row.

My gridview code is as follows:

 <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
        'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'Task_ID',
        'Task_Title',
        'Description',
        //'employee.employee_name',
        //'Assign_task_to',
        'start_date',
         'due_date',
         'priotiy_level',
        // 'complexity_level',
        // 'upload_documents',

        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>
like image 858
user2211486 Avatar asked Aug 25 '16 12:08

user2211486


1 Answers

below code added Task_Title as clickable:

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
        'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
           [
                    'attribute'=>'Task_Title',
                    'format'=>'raw',
                    'value' => function($data)
                    {
                        return
                        Html::a($data->Task_Title, ['task/view','id'=>2], ['title' => 'View','class'=>'no-pjax']);
                    }
            ],

        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>
like image 185
jithin Avatar answered Oct 30 '22 13:10

jithin