Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Gridview row by row css expression

Tags:

gridview

yii2

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.

like image 989
Jonnny Avatar asked Oct 15 '14 00:10

Jonnny


1 Answers

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 [];
      }
    },
like image 184
user1852788 Avatar answered Sep 29 '22 21:09

user1852788