當我使用下面的代碼時,它將覆蓋動作列刪除/更新鏈接。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