根据 CGridView 中的列值更改行颜色

编程入门 行业动态 更新时间:2024-10-21 11:35:09
本文介绍了根据 CGridView 中的列值更改行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 19:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   CGridView   列值更

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!