我是yii2的新手。我已经使用CRUD Generator创建了一个gridview。我想使gridview的行可单击,就像单击视图时一样。它应该导航到该行的查看页面。
代码如下。
` <?= 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'],
],
]); ?>`
最佳答案
下面的代码将Task_Title
添加为可点击的:
<?= 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'],
],
]); ?>