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

心已入冬 提交于 2019-12-04 13:54:12

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/22849880/angularjs-change-color-of-a-cell-based-on-a-condition-ng-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!