我正在尝试通过检查单元格的值来取消在 uiGrid 中编辑单元格。知道如何取消以及如何通过检查单元格值进行编辑吗?
gridApi.edit.on.beginCellEdit($scope, function (rowEntity, colDef) {
if (rowEntity.status > 4)/**/
{
// Cancel edit so that edit never applies
}
else
{
//let editing applied (which normally executes)
}
});
提前致谢1
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;
});
}]);
我希望这有帮助