[ui-grid 3.0.0-rc16] Unable to change value of 'enableCellEdit' for a column definition after initial grid load
Hello,
I want to be able to allow the user to add a new rows and initialize all of the columns of that row...but certains columns should then become non-editable after initial initialization (particularly, the one composing the key on the database).
Ex: $scope.columnsSelected = [ {field: 'id', displayName: 'Identifier', enableCellEdit: false}, ... {field: 'startDate', displayName: 'Start Date', type: 'date', enableCellEdit: true, cellFilter: 'date:"dd-MMM-yyyy"'}, } ];
$scope.gridOptions = {
columnDefs: 'columnsSelected',
data: $scope.myData,
enableFiltering: true,
... }
Without even trying to modify enableCellEdit property on the $scope.columnsSelected[0].enableCellEdit = true....I see an error on the browser.
TypeError: undefined is not a function at Grid.getColDef (http://localhost:9091/bower_components/angular-ui-grid/ui-grid.js:3636:43) at Grid.buildColumns (http://localhost:9091/bower_components/angular-ui-grid/ui-grid.js:3733:17) at dataWatchFunction (http://localhost:9091/bower_components/angular-ui-grid/ui-grid.js:2923:37) at Object.$watchCollectionAction as fn at Scope.$digest (http://localhost:9091/bower_components/angular/angular.js:12541:29) at Scope.$apply (http://localhost:9091/bower_components/angular/angular.js:12806:24) at done (http://localhost:9091/bower_components/angular/angular.js:8379:45) at completeRequest (http://localhost:9091/bower_components/angular/angular.js:8593:7) at XMLHttpRequest.xhr.onreadystatechange (http://localhost:9091/bower_components/angular/angular.js:8532:11)angular.js:10072 (anonymous function)angular.js:7364 (anonymous function)angular.js:12560 Scope.$digestangular.js:12806 Scope.$applyangular.js:8379 doneangular.js:8593 completeRequestangular.js:8532 xhr.onreadystatechange
Is there any way to do this?
This plnkr can be a starting point. http://plnkr.co/edit/2A7jsaCZvBRu8iV615F1
You've based off a plunker that uses address.street as one of the column data fields. It is unhappy when address doesn't exist on the object. I've updated the plunker to create an empty object for address, which appears to make the error go away.
http://plnkr.co/edit/I1yZNdWKAPCqcicjq9Mz?p=preview
I accidentally closed sorry. I will verify this and close if it works.
So is the answer to the original question to use a "cellEditiableCondition" function...to be able to dynamically change whether a column is editable or not after the initial load?
@PaulL1
Currently there's no way to change editable after initial definition. It is probably another flavour of #1819, so we could look at it there, but if cellEditableCondition works for you then yes you should use it.
No comment for over 2 weeks, assuming original raiser has resolved their issue.
Actually, using cellEditableCondition did not work for me (in terms of dynamically changing a column from editable initially, to non-editable there on out).
But you did mention I should look at #1819 @PaulL1
Re-opening this. But if you still think I should just check on #1819, please feel free to reclose.
This worked for me.
onRegisterApi: function(gridApi){
vm.gridApi = gridApi;
if (condition){
vm.gridOptions.enableCellEdit = true;
},
appScopeProvider: vm,
This worked for me.
onRegisterApi: function(gridApi){ vm.gridApi = gridApi; if (condition){ vm.gridOptions.enableCellEdit = true; }, appScopeProvider: vm,
Can you explain it? I am not clear on this.