AngularJS:根据条件NG网格单元的变色 [英] AngularJS: change color of a cell based on a condition ng-grid

查看:815
本文介绍了AngularJS:根据条件NG网格单元的变色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是 plnkr code。我想改变年龄单元格的颜色,他们的警报属性为true的所有行。我不知道该怎么做。我没有为警报一个单独的列。

Here is the plnkr code. I want to change the color of the age cell for all the rows that their alert property is true. I am not sure how to do it. I don't have a separate column for the alert.

推荐答案

在这里你去。请参阅此修改 <大骨节病> PLUNKER 。这里逃逸单引号,但缩进的模板,更好的可读性。

Here you go. Refer this modified PLUNKER. Escaping single quote here but indenting the template for better readability.

<div class="ngCellText" 
     ng-class="{\'green\': row.getProperty(\'alert\') == \'true\' }">
         {{ row.getProperty(col.field) }}
</div>

以上情况是,当警报是字符串再布尔值presentation(真/假)。当警报是布尔值,然后将模板变得不那么笨拙:

Above case is when alert is the string representation of booleans ("true"/"false"). When alert is boolean, then the template becomes less clumsy:

<div class="ngCellText" ng-class="{\'green\': row.getProperty(\'alert\') }">
         {{ row.getProperty(col.field) }}
</div>

更新:结果
为了减少一些冗长绕来绕去那里,我们可以直接使用 row.entity.alert

<div class="ngCellText" 
     ng-class="{\'green\': row.entity.alert == \'true\' }">
         {{ row.getProperty(col.field) }}
</div>

这篇关于AngularJS:根据条件NG网格单元的变色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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