Yii2 Gridview逐行css表达式 [英] Yii2 Gridview row by row css expression
本文介绍了Yii2 Gridview逐行css表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按行css表达式做一行的正确方法是什么?在Yii 1中是rowCssClass。我无法弄清楚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'];
}
},
我不确定在哪里获取参数这个函数从处理dataProvider的时候开始。
I'm unsure where to get the parameters for the function from when dealing with the dataProvider though.
推荐答案
使用$ model替换$ data。
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 [];
}
},
这篇关于Yii2 Gridview逐行css表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文