filter for custom column in grid view which is not in table yii2

Viewed 4641

I have added this 'sla_status' field in gridview and every thing is working fine only issue is I am unable to set filter values for this. 'sla_status' is not in my table.

[
            'label' => Yii::t('app','Sla Status'),
            'format' => 'raw',
            'filterType' => GridView::FILTER_SELECT2,
            'filter' => $status,
            'filterWidgetOptions' => [ 
                    'options' => [ 
                            'placeholder' => Yii::t('app','All...' )
                    ],
                    'pluginOptions' => [ 
                            'allowClear' => true 
                    ] 
            ],

            'headerOptions' => ['style' => 'text-align:center;color:#337ab7'],
            'value' => function ($model, $key, $index, $widget)
            {           }   
            ]

and $status is $status = array('0'=>Yii::t('app', 'Inactive'),'1'=>Yii::t('app', 'Active'));

3 Answers

Add a public variable $sla_status and add sla_status as safe in the rules array in search model

public $sla_status;
public function rules()
{
    return [
        [['sla_status'], 'safe'],
    ];
}
Related