首页 > 解决方案 > celltemplate uigrid 中的条件

问题描述

我想更改单元格 ui 网格中的颜色。请帮忙。这是我的图片: 在此处输入图片描述

标签: angularjs

解决方案


你有这个 ID 的单元格模板:

{
    field: 'BookingId',
    displayName: 'ID',
    cellTemplate: function () {
        return '<div class="ui-grid-cell-contents" style="background-color:lightblue;" ng-if="row.entity.BookingId == \'19\'">{{row.entity.BookingId}}</div><div class="ui-grid-cell-contents" style="background-color:LightCoral;" ng-if="row.entity.BookingId == \'18\'">{{row.entity.BookingId}}</div>';
    }
}

它可能是这样的:

{
    field: 'BookingId',
    displayName: 'ID',
    cellTemplate: function () {
        let color = 'white';
        if (row.entity.BookingId.indexOf('C') !== -1) { color = 'lightblue'; }
        else if (row.entity.BookingId.indexOf('V') !== -1) { color = 'lightred'; }
        else if (row.entity.BookingId.indexOf('P') !== -1) { color = 'lightgreen'; }

        return '<div class="ui-grid-cell-contents" style="background-color:' + color + ';" ng-if="row.entity.BookingId == \'19\'">{{row.entity.BookingId}}</div><div class="ui-grid-cell-contents" style="background-color:LightCoral;" ng-if="row.entity.BookingId == \'18\'">{{row.entity.BookingId}}</div>';
    }
},

推荐阅读