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.
在我的变体中:
'rowOptions' => function ($model, $index, $widget, $grid){
return ['style'=>'color:'.$model->status->color.'; background-color:'.$model->status->background_color.';'];
},
就你而言:
'rowOptions' => function ($model, $index, $widget, $grid){
if($model->option->correct_answer == 1){
return ['class' => 'danger'];
}else{
return [];
}
},
这篇关于Yii2 Gridview 逐行 css 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文