Skip to content

[ui-grid 3.0.0-RC.18 as of 2/7]: Unable to change "enableCellEdit" after initial setting #2752

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 Feb 11, 2015 · 4 comments

Comments

@pmariduena
Copy link

Hi all,

I'm trying to create a grid where you can dynamically make 2 of the columns editable (where they were originally non-editable), and then editable->non-editable, programatically.

This is the tutorial I'm trying to follow:
http://ui-grid.info/docs/#/tutorial/113_adding_and_removing_columns

However, I am still unable to toggle a column from read-only to editable (and vice-versa)

Here's the method I wrote to try and get this working (method to toggle this):

            $scope.columns = [
                {field: 'identifier', displayName: 'Identifier*', enableCellEdit: false},
                {field: 'key2', displayName: 'Second key*', editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'pattern',
                    editDropdownOptionsArray: $scope.patternOverridesTypesArray, enableCellEdit: false},
                {field: 'type', displayName: 'Type', enableCellEdit: false},...
///
            ];
            $scope.gridOptions = {
                columnDefs: $scope.columns,
                multiSelect: true,
                enableSelectAll: true,
...
            var unlockPrimaryKeyColumns = function(cellStateArray, editable) {
                $log.log("(un)Locking the primary key columns.");
                var isEditable = !editable;
                for(var i = 0; i < cellStateArray.length; i++) {
                    if ($scope.columns[cellStateArray[i]].enableCellEdit == isEditable) {
                        $scope.columns[cellStateArray[i]].enableCellEdit = editable;
                    }
                }
                for(var i = 0; i < cellStateArray.length; i++) {
                    $log.log("Cell editable state for column: " + cellStateArray[i] + ", is: " + $scope.gridOptions.columnDefs[cellStateArray[i]].enableCellEdit);
                }
                $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
                $log.log("Done (un)locking the primary key columns.");
            };

I call this toggling method from the method I use to add new rows, and on the afterCellEdit callback (under certain circumstances).

It looks like this:

            var unlockPrimaryKeyColumns = function(cellStateArray, editable) {
                $log.log("(un)Locking the primary key columns.");
                var isEditable = !editable;
                for(var i = 0; i < cellStateArray.length; i++) {
                    $log.log("Their state is: " + $scope.gridOptions.columnDefs[cellStateArray[i]].enableCellEdit);
                    if ($scope.columns[cellStateArray[i]].enableCellEdit == isEditable) {
                        $scope.columns[cellStateArray[i]].enableCellEdit = editable;
                    }
                }
                for(var i = 0; i < cellStateArray.length; i++) {
                    $log.log("Cell editable state for column: " + cellStateArray[i] + ", is: " + $scope.gridOptions.columnDefs[cellStateArray[i]].enableCellEdit);
                }
                $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
                $log.log("Done (un)locking the primary key columns.");
            };

Is something missing in the tutorial (a callback I need to implement)? Of this is not supported for CELL event?

@PaulL1
Copy link
Contributor

PaulL1 commented Feb 13, 2015

I am not sure that cell edit is dynamically available - I think it currently is set once upon grid initialisation - so you'd need to repaint the grid to give this effect.

As such, I think it's another instance of #1819

@PaulL1 PaulL1 added this to the 3.0 milestone Feb 13, 2015
@PaulL1 PaulL1 modified the milestones: Future, 3.0 Feb 13, 2015
@pmariduena
Copy link
Author

@PaulL1 regarding above comment on dynamic cell edit, you suggest "repainting the grid". How do I do that? Do I call an api for that?

@PaulL1
Copy link
Contributor

PaulL1 commented Feb 25, 2015

No, you basically need to regenerate the containing div, which then re-renders the entire grid.

@PaulL1
Copy link
Contributor

PaulL1 commented May 27, 2015

I believe this is now dynamic, looking at the code. Closing, please re-raise if this isn't meeting your needs.

@PaulL1 PaulL1 closed this as completed May 27, 2015
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

2 participants