2016-03-15 4 views
0

Я пытаюсь отменить редактирование ячейки в uiGrid, проверив значение ячейки. Любая идея, как отменить и как разрешить редактирование, проверив значение ячейки?Angularjs UiGrid - запретить редактирование ячейки путем проверки данных в gridApi.edit.on.beginCellEdit

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) 
     } 

    }); 

Спасибо advance1

ответ

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


}]); 

Я надеюсь, что эта помощь

+0

http://plnkr.co/edit/yx7F9HGJdYQF7M97HRMx?p=preview – Shad

+0

Благодаря Шад, когда я изменить поле, это не применяется к $ scope, но сетка по-прежнему показывает новое значение и не возвращает его обратно к текущему значению –

Смежные вопросы