Search code examples
angularjsangular-ui-gridui-grid

UI Grid RowTemplate color based on cell value


I am using below rowTemplate. I want to apply the css class "ui-grid-invalid-upload-row" when the Valid ==true. Somehow, it is not working.

<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader, \'ui-grid-invalid-upload-row\': col.colDef["Value"]==true }" ui-grid-cell></div>

Solution

  • I get the above working, I used below to change color based on row.entity.[FieldName]. Posting here hoping someone would get help from it,

    function rowTemplate() {
            return $timeout(function () {
                return '<div ng-class="{ \'ui-grid-invalid-upload-row\': grid.appScope.rowFormatter( row ) }">' +
                            ' <div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader }"   ui-grid-cell></div>' +
                        '</div>';
            });
        }
    
    $scope.rowFormatter = function (row) {
        return row.entity.Value === 'true';
    };