过滤由yii2中的函数处理的gridview列

时间:2018-03-15 05:37:26

标签: yii2

我有一个名为wp_status的列。如果人员A,人员B,人员C,人员D批准某项工作,则列wp_status的值将更改为Approved,否则该值将与数据库中的值相同 - {{1 }}

在gridview中动态更改值的代码是 -

Assigned

模型Workpermit中的函数Status是 -

[
               'label' => 'Status',
               'attribute'=>'wp_status',
'value' => function ($model) {
                   return $model->Status();
               }
            ],

到目前为止,此工作正常。但我不确定如何使用Kartik Select2小部件过滤它。我试着跟着 -

public function Status()
    {

        //$data = Workpermit::findOne($this->id);
        $total = $this->wp_status;

        if($this->wp_type == 'Safe Work Permit' && $this->wp_apoapproval == 'Approved' && $this->wp_spsapproval == 'Approved' && $this->wp_officerapproval == 'Approved'){ 
           $total = 'Approved';            
        }
        return $total;
    }

在这里我收到错误 - [ 'label' => 'Status', 'attribute'=>'wp_status', 'filterType'=>GridView::FILTER_SELECT2, 'filter'=>ArrayHelper::map(Workpermit::Status()->asArray()->all(), 'total', 'total'), 'filterWidgetOptions'=>[ 'pluginOptions'=>['allowClear'=>true], ], 'filterInputOptions'=>['placeholder'=>'Permit Status'], 'value' => function ($model) { return $model->Status(); } ],

enter image description here

1 个答案:

答案 0 :(得分:0)

可能是一个吸气剂

public function getStatus()
{

    //$data = Workpermit::findOne($this->id);
    $total = $this->wp_status;

    if($this->wp_type == 'Safe Work Permit' && $this->wp_apoapproval == 'Approved' && $this->wp_spsapproval == 'Approved' && $this->wp_officerapproval == 'Approved'){ 
       $total = 'Approved';            
    }
    return $total;
}

来电$model->status(状态小写)

[
           'label' => 'Status',
           'attribute'=>'wp_status',
           'value' => function ($model) {
               return $model->status;
           }
        ],