0

I have displayed the values as follows :

1 => "Active", 0 => "Inactive"

1,0 are the db values.

This is my column.

[
            'label' => 'Status',
            'attribute' => 'activeStatus',
            'format' => 'html',
            'value'=>function ($data){return $data->activeStatus ? '<span class="label label-success">Active</span>' : '<span class="label label-danger">Inactive</span>';} 
        ],

How to enable grid filter with Active/Inactive? It can be a dropdownlist or just by typing Active/Inactive.

3
  • I suggest to use a dropDownList(). Commented Apr 6, 2018 at 6:12
  • My db has int value, I display the values like 1 => "Active", 0 => "Inactive", it's not filtering. Commented Apr 6, 2018 at 6:28
  • Just add that array with the 'filter' => ... key and make sure that activeStatus attribute is on the rules() list in the model used for searching. Commented Apr 6, 2018 at 6:50

1 Answer 1

1

GridView

[
    'label' => 'Status',
    'attribute' => 'activeStatus',
    'format' => 'html',
    'value' => function ($data){
        return $data->activeStatus ? '<span class="label label-success">Active</span>' : '<span class="label label-danger">Inactive</span>';
    },
    'filter' => [1 => 'Active', 0 => 'Inactive'],
],

SearchModel

public function rules()
{
    return [
        [['activeStatus'], 'integer'],
        .
        .
        .
    ];
}

// grid filtering conditions
$query->andFilterWhere([
     'activeStatus' => $this->activeStatus,
]);
Sign up to request clarification or add additional context in comments.

2 Comments

Values passing correctly in the url. But it doesn't return values :(
@BeginnerDev Check your searchModel's filter condition and rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.