What is the correct way to do a row by row css expression. In Yii 1 is was rowCssClass. I couldn't figure out how to achieve this with Yii2. I had tried this, but wasn't sure I was on the right lines:
        'rowOptions' => function($model, $key, $index, $grid){
        if($data->option->correct_answer == 1){
            return ['class' => 'danger'];
        }
    },
I'm unsure where to get the parameters for the function from when dealing with the dataProvider though.
Use $model instead $data.
In my variant:
   'rowOptions' => function ($model, $index, $widget, $grid){
      return ['style'=>'color:'.$model->status->color.'; background-color:'.$model->status->background_color.';'];
    },
In your case:
   'rowOptions' => function ($model, $index, $widget, $grid){
      if($model->option->correct_answer == 1){
        return ['class' => 'danger'];
      }else{
        return [];
      }
    },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With