SO-*_*ser 10 php gridview yii2
当我使用下面的代码时,它会覆盖action-column删除/更新链接.
'rowOptions' => function ($model, $key, $index, $grid) {
return [
'id' => $model['id'],
'onclick' => 'location.href="'
. Yii::$app->urlManager->createUrl('accountinfo/update')
.'?id="+(this.id);',
];
},
Run Code Online (Sandbox Code Playgroud)
由于我有很多列,最好在一个地方指定链接网址,而不是在每列中使用以下代码:
'value' => function ($data) {
return Html::url('site/index');
}
Run Code Online (Sandbox Code Playgroud)
那么除了动作列之外,还有哪种方法可以为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}',
],
],
]);
Run Code Online (Sandbox Code Playgroud)
rob*_*sch 12
你可以试试这个.只要用户单击未被其他元素覆盖的td元素,它就会使整行可单击.因此,action列也是可点击行的一部分,但不是glyphicons.
<?= GridView::widget([
...
'rowOptions' => function ($model, $key, $index, $grid) {
return ['data-id' => $model->id];
},
...
]); ?>
<?php
$this->registerJs("
$('td').click(function (e) {
var id = $(this).closest('tr').data('id');
if(e.target == this)
location.href = '" . Url::to(['accountinfo/update']) . "?id=' + id;
});
");
Run Code Online (Sandbox Code Playgroud)
另请参阅event.target的文档:
target属性可以是为事件注册的元素或其后代.将event.target与此进行比较通常很有用,以确定是否由于事件冒泡而处理了事件.当事件冒泡时,此属性在事件委派中非常有用.
| 归档时间: |
|
| 查看次数: |
17100 次 |
| 最近记录: |