2016-07-29 86 views
0

我正在使用下面的rowTemplate。我想在Valid == true時應用css類「ui-grid-invalid-upload-row」。不知何故,它不工作。基於單元格值的UI網格RowTemplate顏色

<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> 
+0

你忘了張貼您正在使用 – doge1ord

+0

可以請你分享更多代碼的rowTemplate。因爲這將有助於看到田野 –

回答

0

我得到了上面的工作,我用下面的顏色來改變row.entity。[FieldName]。張貼在這裏希望有人會從它那裏得到幫助,

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'; 
}; 
0

使用row.entity.yourfieldname如果你想要的顏色

ng-class="{\'green\':true, \'blue\':row.entity.count==1 }"

一個工作plunker是here


如果你只想要應用類細胞使用cellClass代替

$scope.gridOptions = { 
    enableSorting: true, 
    data:'myData', 
    columnDefs: [ 
     { field: 'sv_name', displayName: 'Nombre'}, 
     {field: 'sv_code', displayName: 'Placa'}, 
     { field: 'count', displayName: 'Cuenta', 
     cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 
      if (grid.getCellValue(row,col) == 1) { 
      return 'blue'; 
      } 
      return 'green'; 
     } 
     } 
    ] 
    }; 

一個工作pluncker是here

讓我知道,如果它可以幫助你。

0

我將col.colDef["Value"]==true更改爲col.colDef[\'Value\']。雙引號過早終止ng-class聲明

<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\'] }" ui-grid-cell></div> 

編輯 既然你想基於單元格的值來改變顏色,我想你應該修改cellTemplate代替。

相關問題