style and change value of data shown in gridview

i want to be able to style and change the value of data in a gridview. The styling works if i do

[‘attribute’ => ‘is_active’,

    'header' => 'Active?', 


    'contentOptions'=>function($model, $key, $index, $column) { 


       if($model->is_active == Apiary::ACTIVE)


            return ['style' => 'color:green'];  


        else


        return   ['style' => 'color:red'];  


       }


    ],

however, i also want to display ‘false’ instead of 0 (Apiary::ACTIVE=0), ‘true’ instead of 1, etc., i.e. if($model->is_active ==0) echo ‘False’;

how best do both apply style and conditionally change the value displayed in a gridview cell?

thanks

Check the "value" property of yii\grid\DataColumn.

http://www.yiiframework.com/doc-2.0/yii-grid-datacolumn.html#$value-detail

thanks, that solves half the problem. However, it seems that if I use the $value parameter, then I can’t style the response. for example, if I have the below- how do i then color, bold, etc. the text that i am returning?- thanks:

    ['attribute' => ‘active,


    'header' => 'Active',


    'value'=>function($model) { 

if($model->active ==0)

                return ‘Not Active'; // how to color text?

elseif($model->active ==1)

                return ‘Active'; // how to color text?

else

return ‘Transferred’; // how to color text?

        }


    ],

It may not look very smart, but something like the following will do:




[

    'attribute' => 'is_active',

    'header' => 'Active?', 

    'contentOptions'=>function($model, $key, $index, $column) { 

        if($model->is_active == Apiary::ACTIVE)

            return ['style' => 'color:green'];  

        else

            return ['style' => 'color:red'];  

     },

     'value'=>function($model) { 

         if($model->active ==0)

             return ‘Not Active';

         elseif($model->active ==1)

             return ‘Active';

         else

             return ‘Transferred';

     },

],



thanks- that did it!

Since Yii uses Bootstrap you are better of using a Bootstrap class rather than style as below:

                'contentOptions' => function($model) {
                      if ($model->taskduedt < date("Y-m-d")) {
                          return ['class' => 'table-danger',];
                      } elseif ($model->taskduedt == date("Y-m-d")) {
                          return ['class' => 'table-warning',];
                      }
                        else return ['class' => '',];
                },