我对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'],
],
]); ?>`
答案 0 :(得分:5)
以下代码添加了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'],
],
]); ?>
答案 1 :(得分:1)
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions' => function($model,$index,$key){
return ['id' => $model['id'], 'onclick' => 'alert("Row clicked")'];
}
'columns' => [],
]); ?>