我试图用蓝色标记在UI Grid单元格中编辑。为此,在Activity
事件中,我在行实体中进行了一些更改。 afterCellEdit
函数检查这些标记并返回相应的类名。也使用了cellClass
(在文档中指定)的调用。
以下示例已简化,因为没有检查,已编辑了哪个列。在真正的应用程序中,我有更复杂的代码来标记特定的单元格。但这个例子足以说明问题:
$scope.$apply
列中选择单元格(但不在最后一行)。Company
列更改为true,选择移至下一行,但已编辑单元格中的文本仍为黑色。如何在第3步强制换色而不是4?
http://plnkr.co/edit/SEEf4DPhA3CB1mx7R4I8?p=preview
Edited

var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit', 'ui.grid.cellNav']);
app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.gridOptions = {
enableCellEditOnFocus: true,
columnDefs: [{
field: 'edited',
enableCellEdit: false
},{
field: 'company',
cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
return row.entity.edited ? 'blue' : '';
}
}],
onRegisterApi: function (gridApi) {
gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
if (newValue !== oldValue) {
rowEntity.edited = true;
$scope.$apply();
}
});
}
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
}]);

.grid {
width: 500px;
height: 200px;
}
.blue {
color: blue;
}

答案 0 :(得分:2)
您可以使用notifyDataChange
让uigrid知道值已更改。
juste在您的控制器中注入uiGridConstants
并将$scope.apply()
替换为gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit', 'ui.grid.cellNav']);
app.controller('MainCtrl', ['$scope', '$http','uiGridConstants', function ($scope, $http,uiGridConstants) {
$scope.gridOptions = {
enableCellEditOnFocus: true,
columnDefs: [{
field: 'edited',
enableCellEdit: false
},{
field: 'company',
cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
return row.entity.edited ? 'blue' : '';
}
}],
onRegisterApi: function (gridApi) {
gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
if (newValue !== oldValue) {
rowEntity.edited = true;
gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
}
});
}
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
}]);