I am not sure if I understand your code.
You should not put the html code in your data. So I changed it to:
$scope.gridOptions.data = [ { "field01": "one", "field02": "01", "field03": false, "field04": '', "field05": '', }, { "field01": "two", "field02": "02", "field03": false, "field04": '', "field05": '', }, { "field01": "three", "field02": "03", "field03": false, "field04": '', "field05": '', } ];
Next: in the cell template, pass the link to the mutable value:
{ name: 'field03', field: 'field03', cellTemplate: '<input type="checkbox" ng-model="row.entity.field03" ng-click="$event.stopPropagation(); getExternalScopes().showMe(row.entity.field03)">'}
Note that the showMe()
function now has a parameter:
showMe(row.entity.field03)
In the outer scope, you must respond to the parameter:
$scope.myViewModel = { someProp:'abc', showMe : function(value){ alert('toggled to: '+value); } };
(You really don't need someProp
)
The $scope.toggle()
function can be removed or can be called from showMe()
.
In addition, I added some debugging help to your html to show you that the binding works very well:
<div ng-controller="MainCtrl"> <div ui-grid="gridOptions" external-scopes="myViewModel" class="grid"></div> <hr> {{gridOptions.data | json}} </div>
Here is the Plunker . Is this what you want?
Update:
Here is another Plunker that has a check box in column 4.