Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pmariduena opened this issue Nov 26, 2014 · 9 comments
Milestone

Comments

@pmariduena
Copy link

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

@PaulL1
Copy link
Contributor

PaulL1 commented Dec 10, 2014

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 PaulL1 added this to the 3.0 milestone Dec 10, 2014
@pmariduena
Copy link
Author

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

@pmariduena pmariduena reopened this Dec 10, 2014
@pmariduena
Copy link
Author

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
Copy link
Author

@PaulL1

@PaulL1
Copy link
Contributor

PaulL1 commented Dec 26, 2014

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
Copy link
Contributor

PaulL1 commented Jan 10, 2015

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

@PaulL1 PaulL1 closed this as completed Jan 10, 2015
@pmariduena
Copy link
Author

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.

@justin1291
Copy link

This worked for me.

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

@hanishw
Copy link

hanishw commented Jan 6, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants