我有一个gridview,其中有根据用户授权和其他条件的自定义actioncolumn。由于这种情况,在几行中,只有几行没有操作项按钮。我想隐藏这些行。
我可以按行选项隐藏行。但是我想知道如何根据操作项按钮将其隐藏。
以下是索引视图页面-
<?php
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use frontend\modules\workpermit\models\Workpermit;
use frontend\modules\workpermit\models\Extension;
use frontend\modules\workpermit\models\WpindexSearch;
use frontend\modules\workpermit\models\Aclpath;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\workpermit\models\WorkpermitSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'All Permits';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="workpermit-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Home', ['/site/index'], ['class' => 'btn btn-success']) ?>
<?= Html::a('Refresh', ['/workpermit/workpermit/awsup'], ['class' => 'btn btn-primary']) ?>
</p>
<?php Pjax::begin(['id' => 'allpermitview']); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions' => function($model){
if($model->wp_type == 'Excavation Permit'){
return ['class' => 'hide'];
}
},
'options' => [
'style'=>'overflow: auto; word-wrap: break-word;'
],
'columns' => [
//['class' => 'yii\grid\SerialColumn'],
[
'class' => 'kartik\grid\ExpandRowColumn',
'value' => function($model, $key, $index, $column){
return GridView::ROW_COLLAPSED;
},
'detail' => function($model, $key, $index, $column){
$model = Workpermit::find()->where(['wp_no' => $model->wp_no])->one();
$searchModel = new WpindexSearch();
$aclfileuploadpaths = Aclpath::find()->select('aclp_path')->where(['aclp_wpno'=>$model->wp_no])->column();
// $searchModel->wp_no = $model->wp_no;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$id = $model->wp_no;
if($model->wp_type == 'Safe Work Permit'){
return Yii::$app->controller->renderPartial('_approvalstatussafe', [
'id' => $id,
'model' => $model,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
//'from_date' => $from_date, 'to_date'=>$to_date
]);
}
elseif($model->wp_type == 'Hot Work Permit'){
return Yii::$app->controller->renderPartial('_approvalstatushot', [
'id' => $id,
'model' => $model,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
//'from_date' => $from_date, 'to_date'=>$to_date
]);
}
elseif($model->wp_type == 'Excavation Permit'){
return Yii::$app->controller->renderPartial('_approvalstatusexcav', [
'id' => $id,
'model' => $model,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
//'from_date' => $from_date, 'to_date'=>$to_date
]);
}
elseif($model->wp_type == 'Confined Space Permit'){
return Yii::$app->controller->renderPartial('_approvalstatusconfined', [
'id' => $id,
'model' => $model,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
//'from_date' => $from_date, 'to_date'=>$to_date
]);
}
},
],
'wp_no',
[
'label' => 'WP Type',
'attribute' => 'permittyp',
'value' => 'permittype.wpt_short',
'filterType'=>GridView::FILTER_SELECT2,
'filter'=>ArrayHelper::map(Workpermit::find()->asArray()->all(), 'wp_type', 'wp_type'),
'filterWidgetOptions'=>[
'pluginOptions'=>['allowClear'=>true],
],
'filterInputOptions'=>['placeholder'=>'Type'],
],
[
'label' => 'Status',
//'attribute'=>'status',
'attribute'=>'wp_status',
'filterType'=>GridView::FILTER_SELECT2,
'filter'=>ArrayHelper::map(Workpermit::Find()->asArray()->all(), 'wp_status', 'wp_status'),
'filterWidgetOptions'=>[
'pluginOptions'=>['allowClear'=>true],
],
'filterInputOptions'=>['placeholder'=>'Permit Status'],
'contentOptions' => function($model, $key, $index, $column){
if($model->wp_status == 'Available'){
return['style' => 'background-color:red'];
}elseif($model->wp_status == 'Approved'){
return['style' => 'background-color:green'];
}elseif($model->wp_status == 'Work in Progress'){
return['style' => 'background-color:yellow'];
}elseif($model->wp_status == 'Completed'){
return['style' => 'background-color:blue'];
}
}
],
'wp_date',
//'wp_time',
'wp_validto',
[
'attribute'=>'wp_plant',
'filterType'=>GridView::FILTER_SELECT2,
'filter'=>ArrayHelper::map(Workpermit::find()->asArray()->all(), 'wp_plant', 'wp_plant'),
'filterWidgetOptions'=>[
'pluginOptions'=>['allowClear'=>true],
],
'filterInputOptions'=>['placeholder'=>'Plant'],
],
[
'attribute'=>'wp_area',
'filterType'=>GridView::FILTER_SELECT2,
'filter'=>ArrayHelper::map(Workpermit::find()->asArray()->all(), 'wp_area', 'wp_area'),
'filterWidgetOptions'=>[
'pluginOptions'=>['allowClear'=>true],
],
'filterInputOptions'=>['placeholder'=>'Area'],
],
//'wp_area',
'wp_jobdesc',
[
'label' => 'View',
'content' => function ($model, $key, $index, $column) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', ['viewall', 'id' => $model->wp_no])
. ' ' .Html::a('<span class="glyphicon glyphicon-print"></span>', ['/workpermit/workpermit/printpermit', 'id' => $model->wp_no]);
}
],
[ 'label' => 'Action',
'content' => function ($model, $key, $index, $column) {
//The Supervisor Conditions//
if ($model->wp_status == 'Assigned' && Yii::$app->user->can('s_jsapproval')) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['updateapproval', 'id' => $model->wp_no]);
}
elseif ($model->wp_type == 'Safe Work Permit' && $model->wp_apoapproval == 'Approved' && $model->wp_spsapproval == 'Approved' && $model->wp_officerapproval == 'Approved' && Yii::$app->user->can('s_jsapproval') && $model->wp_jc != 'Completed' && ($model->wp_status == 'Approved' || $model->wp_status == 'Work in Progress' || $model->wp_status == 'Assigned')) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['updateassignwp', 'id' => $model->wp_no]);
}
elseif ($model->wp_type == 'Hot Work Permit' && $model->wp_apoapproval == 'Approved' && $model->wp_spsapproval == 'Approved' && $model->wp_officerapproval == 'Approved' && $model->wp_emsuper == 'Approved' && $model->wp_plsuper == 'Approved' && Yii::$app->user->can('s_assignwp') && ($model->wp_status == 'Approved' || $model->wp_status == 'Work in Progress')) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['updateassignwp', 'id' => $model->wp_no]);
}
elseif ($model->wp_type == 'Confined Space Permit' && ($model->wp_status == 'Assigned' || $model->wp_status == 'Work in Progress' || $model->wp_status == 'Approved') && Yii::$app->user->can('s_assignwp')){
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['updateassignwp', 'id' => $model->wp_no]);
}
}
],
],
]); ?>
<?php Pjax::end(); ?>
</div>
<?php
/* start getting the another permit Type */
$script = <<< JS
$('#workpermit-wp_spost13').on('click',function(e){
$.pjax.reload({container: "#allpermitview"});
});
JS;
$this->registerJs($script);
/* end getting the another permit Type */
?>
答案 0 :(得分:0)
几个选项供您选择:
注意:您还可以在搜索模型中应用可选过滤器。
class SomeController extends Controller
{
public function actionIndex()
{
$this->layout = "@app/views/layouts/main-app";
$searchModel = new WorkpermitSearch ();
$queryParams = Yii::$app->request->queryParams;
$dataProvider = $searchModel->search($queryParams);
$dataProvider->query->andWhere(['or',
['wp_type' => 'Safe Work Permit')],
['wp_type'=> 'Hot Work Permit'],
])
->orderBy(['wp_type' => SORT_DESC ]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//'emptyCell'=>'-',
//'formatter' => ['class' => 'yii\i18n\Formatter', 'nullDisplay' => ''], //Hide "not set" fields.
//'tableOptions' => ['class' => 'table'],
//'options' => ['style' => 'font-size: 1.2em;'],
'rowOptions' => function($model, $key, $index, $grid){
if ($model->wp_type == 'Safe Work Permit'){
return ['style' => 'visibility:collapse;'];
} else {
return ['style' => 'visibility:visible;'];
}
},
...