如何在UI网格中的celleditablecondition中传递row.entity?

时间:2017-03-28 13:30:37

标签: angularjs angular-ui ui-grid

我正在尝试根据同一行中其他单元格的内容设置cellEditableCondition

为此我如何将row.entity传递给cellEditableCondition?

我尝试将row作为arguement传递给函数define onceEditableCondition但该行对象没有entity属性。

我想要以下内容:

columnDefs: [{
  name: 'column1',
  field: 'name',
  cellEditableCondition: function(row) {
    return row.entity.lastname === 'Adams'
  }

}, {
  name: 'column2',
  field: 'lastname'
}]

1 个答案:

答案 0 :(得分:1)

对代码的这一小调整应该这样做:



var app = angular.module('app', ['ui.grid', 'ui.grid.edit']);
app.controller('MainCtrl', ['$scope', function($scope) {
  $scope.gridOptions = {
    columnDefs: [{
      name: 'column1',
      field: 'name',
      cellEditableCondition: function(scope) {
        return scope.row.entity.lastname === 'Adams'
      }
    }, {
      name: 'column2',
      field: 'lastname'
    }],
    data: [{name: "Tim", lastname: "Harker"},
           {name: "Akash", lastname: "Adams"}]
  }
}]);

div[ui-grid] {
  height: 130px;
}

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.0.2/ui-grid.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.0.2/ui-grid.min.css" />
<div ng-app="app" ng-controller="MainCtrl">
  <div ui-grid="gridOptions" ui-grid-edit>
  </div>
</div>
&#13;
&#13;
&#13;

如果您有任何其他问题,请与我们联系。如果需要,很乐意进一步提供帮助。