ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

[ui-grid 3.0.0-rc16] Unable to change value of 'enableCellEdit' for a column definition after initial grid load

Open pmariduena opened this issue 12 years ago • 9 comments

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

pmariduena avatar Nov 26 '14 22:11 pmariduena

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

PaulL1 avatar Dec 10 '14 06:12 PaulL1

I accidentally closed sorry. I will verify this and close if it works.

pmariduena avatar Dec 10 '14 14:12 pmariduena

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?

pmariduena avatar Dec 23 '14 19:12 pmariduena

@PaulL1

pmariduena avatar Dec 23 '14 19:12 pmariduena

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.

PaulL1 avatar Dec 26 '14 20:12 PaulL1

No comment for over 2 weeks, assuming original raiser has resolved their issue.

PaulL1 avatar Jan 10 '15 21:01 PaulL1

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.

pmariduena avatar Jan 12 '15 14:01 pmariduena

This worked for me.

onRegisterApi: function(gridApi){
    vm.gridApi = gridApi;
     if (condition){
          vm.gridOptions.enableCellEdit = true;
     },
     appScopeProvider: vm, 

justin1291 avatar Mar 01 '17 18:03 justin1291

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.

hanishw avatar Jan 06 '20 10:01 hanishw