简体   繁体   中英

Angularjs and ng-grid: how handle checkbox

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?

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

ng-change="emitEndCellEdit()"

with

$scope.emitEndCellEdit = function() { $scope.$emit('ngGridEventEndCellEdit') }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM