I have a gridview in which I have custom actioncolumn according to user authorization and other conditions. Due to this conditions, in few rows, there are no action item button for few rows. I want to hide these rows.

I can hide the row on condition by rowoption. But I want to know how can I hide it according to the action item button.

Following is the index view page -

<?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 Answers