简体   繁体   English

AngularJS和ng-grid:如何处理复选框

[英]Angularjs and ng-grid: how handle checkbox

in angulajs i have a ng-grid that i fill with data returned from a server. 在angulajs中,我有一个ng-grid,其中填充了从服务器返回的数据。 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: 现在,当我编辑某些单元格时,我想将已编辑的行保存回数据库,以便处理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? 选中/取消选中复选框时,如何发出ngGridEventEndCellEdit? Or how can handle that? 或如何处理?

What about emitting ngGridEventEndCellEdit from the checkbox ng-change function? 从复选框ng-change函数发出ngGridEventEndCellEdit怎么样?

ng-change="emitEndCellEdit()"

with

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

Try to add ng-change="edit(row)" to your cell template. 尝试将ng-change =“ edit(row)”添加到您的单元格模板中。 Handle all your stuff inside $scope.edit function. 在$ scope.edit函数中处理所有内容。 You should receive clicked grid data as a parameter. 您应该收到单击的网格数据作为参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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