简体   繁体   English

如何自定义有角度的ui-grid行背景颜色?

[英]How to customize angular ui-grid row background color?

I am trying to change background color of angular ui-grid row based on condition so if riskValue is 1 trying to make it red and if value is 2 row background color should be Yellow. 我试图根据条件更改有角度的ui网格行的背景颜色,因此,如果RiskValue为1,则尝试使其变为红色,如果值为2,则行背景颜色应为黄色。 Any easy way to achieve this task ? 任何简单的方法来完成此任务?

config.js config.js

"columnDefs": [{
        "name": "Ticket Number",
        "field": "ticketNum",
        "width": 120
    },
    {
        "name": "Asset Id ",
        "field": "assetID",
        "width": 100
    },
    {
        "name": "Severity",
        "field": "severity",
        "width": 100
    },
    {
        "name": "Risk Index",
        "field": "riskIndex",
        "width": 100
    },
    {
        "name": "Risk Val",
        "field": "riskValue",
        "cellTemplate": "<div ng-if=\"row.entity.Comments_Col1 != 'none'\" title={{row.entity.riskValue}} \" ><div style='white-space:nowrap;border-bottom: 1px solid red !important; height:100%;width:100%;'>{{row.entity.riskValue}}</div></div>",
        "sort": {
            "direction": "aesc",
            "priority": 0
        },
        "width": 100,
        "visible": false
    }
],

You can use gridOptions.cellClass 您可以使用gridOptions.cellClass

cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
    if (row.entity.riskValue === 1) 
        return 'red';
    if (row.entity.riskValue === 2)
        return 'yellow';
}

where red and yellow are css classes. 其中redyellow是css类。

This method requires adding the function to all of your columnDefs but allows to choose only some columns, which should have changed background color. 此方法需要将功能添加到所有columnDefs中,但只能选择一些应该更改了背景色的列。

Sample: http://plnkr.co/edit/Xie68a3sT9CXTdCuI3tq?p=preview 样本: http//plnkr.co/edit/Xie68a3sT9CXTdCuI3tq?p = preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM