根据 CGridView 中的列值更改行颜色 [英] Change the Row Color Based on the Column value in CGridView

查看:33
本文介绍了根据 CGridView 中的列值更改行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Yii 中,CGridView 在行中有它自己的背景颜色.但我想要做的是根据列之一的值突出显示特定行.

In Yii, CGridView has it's own background color in the row. But what I want to do is highlight particular row based on the value of one of the column.

例如,我有三列,id、name、status.现在,如果状态值为 Inactive 或 0,我应该用某种颜色突出显示该行.

For Instance, I have three column, id, name, status. Now, If the Value of status is Inactive or 0, I should highlight the row with some color.

我简要地阅读了课程参考并搜索了该网站.但是找不到相关的解决方法.如果有一些示例或朝着正确解决方案的方向,那将不胜感激.

I read the class reference briefly and searched this site as well. But could not find the relevant solution. If some example or some direction toward the right solution, that would be much appreciated.

谢谢,乌杰瓦尔

推荐答案

CGridView 'rowCssClassExpression' 是获得你想要的东西的方式.

CGridView 'rowCssClassExpression' is the way to get what you want.

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'rowCssClassExpression'=>'($data->myFlag==0)?"normal":"especial"',
    'columns'=>array(
    ...
    ),
));

您也可以调用自定义的 php 函数,并将 $data 变量传递给它.该函数应该返回给定行的类名:)

You can also call a custom php function, and pass the $data variable to it. That function should return the class name for the given row :)

这篇关于根据 CGridView 中的列值更改行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆