3

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'));

deepak
  • 62
  • 2
  • 8
  • If its in a related table then you need to add this table with relation and then filter it using that – Muhammad Amjad Jun 05 '17 at 03:36
  • no it is not any table, I am computing the values for 'sla status' based on the due dates for the task's.So this field actually doesn't exist anywhere in the db itself. – deepak Jun 05 '17 at 05:42
  • I think the filter will be based on dates nor based on the status... the second thought is that you need to compare the results and use afterFind event to filter the data or use internalFind – Muhammad Amjad Jun 06 '17 at 09:34

3 Answers3

2

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'],
    ];
}
0

in Search model you should add attribute sla_status and in search() add required where. for example:

class TaskSearch extends Task{
public $sla_status;
public function search($params){ 
    $query = Task::find();
    if($this->sla_status){ $query->andWhere(...); } 
}}
0

Add your field "sla_status" to "safe" in rules method of your model or search model like

[['sla_status'], 'safe'],

Ivoglent Nguyen
  • 504
  • 3
  • 9