当我使用下面的代码时,它将覆盖动作列删除/更新链接。GridView行作为链接,除了Yii2中的动作列项目
'rowOptions' => function ($model, $key, $index, $grid) {
return [
'id' => $model['id'],
'onclick' => 'location.href="'
. Yii::$app->urlManager->createUrl('accountinfo/update')
.'?id="+(this.id);',
];
},
正如我有许多列这将有利于在一个地方指定链接的URL,而不是在每列中使用下面的代码:
'value' => function ($data) {
return Html::url('site/index');
}
那么,有没有给链接,任何最好的方法GridView中除了动作列外的整行?
编辑: 完整的GridView
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions' => function ($model, $index, $widget, $grid) {
if ($widget == 1)
return [
'id' => $model['id'],
'onclick' => 'location.href="'
. Yii::$app->urlManager->createUrl('accountinfo/update')
. '?id="+(this.id);'
];
},
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
'f_name',
'l_name',
'address',
'country',
'state',
'city',
'pincode',
[
'attribute' => 'status',
'value' => function ($model, $key, $index, $column) {
return $model->status == '1' ? 'Enabled' : 'Disabled';
},
'filter' => [1 => 'Enabled', 0 => 'Disabled'],
],
'card',
'note',
'balance',
'is_new',
[
'attribute' => 'is_new',
'value' => function ($model, $key, $index, $column) {
return $model->is_new == '1' ? 'Yes' : 'No';
},
'filter' => [1 => 'Yes', 0 => 'No'],
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
],
],
]);
你能解释一下更多细节吗?添加完整的'GridView'渲染代码。也许举一些例子。我不明白,为什么需要它? – arogachev 2015-02-07 10:53:49
添加了我的网格视图..我想要重定向它,以更新页面时单击该行。问题是,当我点击删除按钮,它被重定向到更新页面,由于** rowOptions ** – 2015-02-07 11:05:51
Btw:'Full GridView'中rowOptions的参数不正确。它应该是($ model,$ key,$ index,$ grid),而不是($ model,$ index,$ widget,$ grid)。 – robsch 2015-02-12 17:31:11