0

is there a way to disable/enable cell edit of the grid. for example i have a master-detail form screen. when user wants to analyze a record, i disable all controls of the form with ng-disabled. but i could not prevent editing the grid. i tried "cellEditableCondition" option. But, i runs only when grid is loading. it would be nice if grid have an option like "disableEdit" and accepts a scope variable. when i open my form in edit mode, grid would be editable, and when in view mode grid would be disabled.

2
  • Plz post some code . Commented Jun 8, 2015 at 16:04
  • Have you tried to change the column definition and then notify grid using $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN); as explained here? Commented Jun 8, 2015 at 16:41

1 Answer 1

2

i found a solution. you can use cellEditableCondition attribute of the grid column. if you apply a function to this attribute, you can enable/disable dynamically cells. here is a plunker:

 $scope.canEdit = function () { return $scope.pageOptions.isView; };

 $scope.pageOptions = { isView : false};

$scope.gridOptions1 = {
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 }
],
isRowSelectable:function(row){if(row.entity['age']>30) return true; return false;},
onRegisterApi: function( gridApi ) {
  $scope.gridApi = gridApi;
}
};

http://plnkr.co/edit/md9AOA64Zn67KqhNmhZT?p=preview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.