AngularJS: change color of a cell based on a condition ng-grid

痴心易碎 提交于 2019-12-03 08:52:34

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>

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>

UPDATE:
To reduce some verbosity going around there, we can directly use row.entity.alert:

<div class="ngCellText" 
     ng-class="{\'green\': row.entity.alert == \'true\' }">
         {{ row.getProperty(col.field) }}
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!