I'm trying to put in a page that loads a list of results, with a checkbox each, shown with AngularJS, a checkbox that when clicking, check all the checkboxes in the list. For this, I created this checkbox like this:
<input title="Marcar todos" id="sf_admin_list_batch_checkbox" type="checkbox" onclick="checkAll();" />
Then I go through the variable that will store the Json that comes from the action (var JsonData)
<tr ng-repeat="item in data">
<input type="checkbox" ng-model="item.checked" class="sf_admin_batch_checkbox">
Finally I try to create a function so that it marks all, but I can not get it to work:
<script type="text/javascript">
function checkAll()
{
$scope.data = {};
$scope.checkAll = function () {
if ($scope.selectedAll) {
$scope.selectedAll = true;
} else {
$scope.selectedAll = false;
}
angular.forEach($scope.Items, function (item) {
item.Selected = $scope.selectedAll;
});
}
}
</script>
The problem is that I do not know what to put in the $ scope.data
I do not know if I'm on the right track
Greetings. Thanks
I currently have the input
<input title="Marcar todos" id="sf_admin_list_batch_checkbox" type="checkbox" onclick="checkAll();" />
and a script that has stopped working when modifying the input of the loop
<script type="text/javascript">
function checkAll()
{
var boxes = document.getElementsByTagName('input'); for(var index = 0; index < boxes.length; index++) { box = boxes[index]; if (box.type == 'checkbox' && box.className == 'sf_admin_batch_checkbox') box.checked = document.getElementById('sf_admin_list_batch_checkbox').checked } return true;
}
</script>