var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit' ]);
app.controller('MainCtrl', ['$scope', '$http', '$interval', 'uiGridConstants', function ($scope, $http, $interval, uiGridConstants) {
$scope.edit = true;
$scope.canEdit = function() { return $scope.edit; };
$scope.gridOptions = {
enableRowSelection: true,
enableSelectAll: true,
enableFiltering: true,
columnDefs: [
{ name: 'name', width: '30%', cellEditableCondition : $scope.canEdit },
{ name: 'gender', width: '20%', cellEditableCondition : $scope.canEdit },
{ name: 'age', width: '20%', cellEditableCondition : $scope.canEdit },
{ name: 'company', width: '25%', cellEditableCondition : $scope.canEdit },
{ name: 'state', width: '35%', cellEditableCondition : $scope.canEdit },
{ name: 'balance', width: '25%', cellEditableCondition : $scope.canEdit }
],
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.selection.on.rowSelectionChanged($scope, function (rowEntity, colDef) {
console.log(rowEntity.entity)
if (rowEntity.entity.id > 4)/**/
{
// Cancel edit so that edit never applies
$scope.edit = false;
}
else
{
//let editing applied (which normally executes)
$scope.edit = true;
}
});
}
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
}]);
Я надеюсь, что эта помощь
http://plnkr.co/edit/yx7F9HGJdYQF7M97HRMx?p=preview – Shad
Благодаря Шад, когда я изменить поле, это не применяется к $ scope, но сетка по-прежнему показывает новое значение и не возвращает его обратно к текущему значению –