<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
'name',
'first',
'second',
'third',
'note',
[
'label' => '状态',
'attribute' => 'status',
'filter' => ['1'=>'开启','2'=>'关闭'],
'value' => function($model)
{
return $model->status == 1 ? '开启' : '关闭';
}
],
['class' => 'yii\grid\ActionColumn',
'header' => '操作',
'headerOptions'=> ['width'=> '190'],
'template' => '{update} {delete} {change}',
"buttons" => [
"update" => function ($url)
{
$options = [
'title' => '修改',
'data-method' => 'post',
'data-pjax' => '0',
];
return Html::a('<button class="btn btn-sm btn-info">修改</button>', $url, $options);
},
"delete" => function ($url)
{
$options = [
'title' => '删除',
'aria-label' => '删除',
'data-confirm' => '确认删除该AS规则,删除后符合规则列表将随之更变。',
'data-method' => 'post',
'data-pjax' => '0',
];
return Html::a('<button class="btn btn-sm btn-danger">删除</button>', $url, $options);
},
"change" => function ($url, $model)
{
$options = [
'title' => $model->status == 1 ? '关闭' : '开启',
'data-method' => 'post',
'data-pjax' => '0',
];
if ($model->status == 1)
return Html::a('<button class="btn btn-sm btn-warning">关闭</button>', $url, $options);
else
return Html::a('<button class="btn btn-sm btn-success">开启</button>', $url, $options);
},
]
],
],
]); ?>
<?php Pjax::end(); ?>
yii2自定义GridView和ActionColumn
最新推荐文章于 2021-03-23 22:08:27 发布