0

in angulajs i have a ng-grid that i fill with data returned from a server. The field "Active" is a boolean so i have make a template to show a checkbox:

$scope.gridOptions = { data: 'myData', enableCellSelection: true,
                       enableRowSelection: false, enableCellEdit: true,
                       columnDefs: [{ field: 'Id', displayName: 'Id', visible: false },
                                    { field: 'Name', displayName: 'Name', enableCellEdit: true },
                                    { field: 'Active', displayName: 'Active', enableCellEdit: true, cellTemplate: '<input type="checkbox" ng-model="row.entity.Active" >' }]

Now, when i edit some cell, i want save back to the database the edited row and so i handle the ngGridEventEndCellEdit:

$scope.$on('ngGridEventEndCellEdit', function (data) {
   ....
}

event. In effect when i edit the cell "Name" the above handler is called but when i check/uncheck the checkbox Active, that event isn't called. How can i emit the ngGridEventEndCellEdit when i check/uncheck the checkbox? Or how can handle that?

4
  • would an ng-change function in the checkbox element work? Commented Apr 23, 2014 at 12:59
  • i think it could work but i have two function to handle the edit? (one handler is $scope.$on('ngGridEventEndCellEdit', function (data) that is called when i edit, for example, the Name cell, and another handler that is called when i click the checkbox? Commented Apr 23, 2014 at 14:03
  • what is in the $scope.$on('ngGridEventEndCellEdit', function (data) {}) function ? Commented Apr 23, 2014 at 14:12
  • data is the edited data passed by the ng-grid to the custom handler Commented Apr 23, 2014 at 14:37

2 Answers 2

1

What about emitting ngGridEventEndCellEdit from the checkbox ng-change function?

ng-change="emitEndCellEdit()"

with

$scope.emitEndCellEdit = function() { $scope.$emit('ngGridEventEndCellEdit') }
Sign up to request clarification or add additional context in comments.

Comments

0

Try to add ng-change="edit(row)" to your cell template. Handle all your stuff inside $scope.edit function. You should receive clicked grid data as a parameter.

2 Comments

So i have a function $scope.edit to handle the check/uncheck on the checkbox and $scope.$on('ngGridEventEndCellEdit', function (data) when i edit the other cells?
Look at klode answer. I was thinking about similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.