Skip to content

Commit

Permalink
feat(gridEdit): Pass triggerEvent to cellEditableCondition fn call
Browse files Browse the repository at this point in the history
Need to know what triggered the edit request to be able to decide
if edit should be allowed or not.
  • Loading branch information
karlkerem authored and vishalnarewade committed Nov 6, 2017
1 parent 8238ca7 commit a0f7026
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion misc/tutorial/201_editable.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ __ColumnDef Options__:
- `enableCellEdit` (default: `false` for columns of type `'object'`, `true` for all other columns) - `true` will enable
editing and `false` will disable it.
- `cellEditableCondition` (default: `true`) Can be set to a boolean or a function that will be called with the cellScope
to determine if the cell should be invoked in edit mode.
and triggerEvent to determine if the cell should be invoked in edit mode.
- `type` (default: `'string'`) If set to `'number'`, `'boolean'` or `'date'` the default editor provided for editing will be numeric
or boolean or date editor respectively. If set to `'object'` the column will not be editable by default. Be aware that this
`type` column is also used for other purposes within ui-grid, including the sorting logic.
Expand Down
14 changes: 7 additions & 7 deletions src/features/edit/js/gridEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
* If false, then editing of cell is not allowed.
* @example
* <pre>
* function($scope){
* //use $scope.row.entity and $scope.col.colDef to determine if editing is allowed
* function($scope, triggerEvent){
* //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
* return true;
* }
* </pre>
Expand Down Expand Up @@ -209,8 +209,8 @@
* @description If specified, either a value or function evaluated before editing cell. If falsy, then editing of cell is not allowed.
* @example
* <pre>
* function($scope){
* //use $scope.row.entity and $scope.col.colDef to determine if editing is allowed
* function($scope, triggerEvent){
* //use $scope.row.entity, $scope.col.colDef and triggerEvent to determine if editing is allowed
* return true;
* }
* </pre>
Expand Down Expand Up @@ -592,10 +592,10 @@
}
}

function shouldEdit(col, row) {
function shouldEdit(col, row, triggerEvent) {
return !row.isSaving &&
( angular.isFunction(col.colDef.cellEditableCondition) ?
col.colDef.cellEditableCondition($scope) :
col.colDef.cellEditableCondition($scope, triggerEvent) :
col.colDef.cellEditableCondition );
}

Expand Down Expand Up @@ -732,7 +732,7 @@
return;
}

if (!shouldEdit($scope.col, $scope.row)) {
if (!shouldEdit($scope.col, $scope.row, triggerEvent)) {
return;
}

Expand Down

0 comments on commit a0f7026

Please sign in to comment.