Kartik Grid Filter

Guys,

I’m using kartik\grid\GridView and one of my Columns is




[

      'class'=>'kartik\grid\BooleanColumn',

      'attribute'=>'active', 

      'vAlign'=>'middle',

      'filterType'=>GridView::FILTER_CHECKBOX,

],



for setting checkbox checked as default, I defined a property $active=1 in ModelSearch class.

Is there any clean way to do this?

You can pass your own value like this




[

      'class'=>'kartik\grid\BooleanColumn',

      'attribute'=>'active', 

      'vAlign'=>'middle',

      'filterType'=>GridView::FILTER_CHECKBOX,

      'value'=>function($model,$key,$index,$widget) { 

            return ($model->active == null) ? true : false; 

       },

],



On relooking at the post topic, I think you are asking for a default value for your grid filter. If that is so, you can edit your $searchModel->search() function and set:




$this->active = true;

// before this line

if (!($this->load($params) && $this->validate()))



You are right.there is no need to define $active twice.

Also thanks for such a great extension.