how to count the number of selecte/unselected checkbox items using angularjs?
my html
<label class="col-xs-5 pull-left" style="font-weight: bold; margin-left: 4px; margin-top: -17px;" >You have choose <font size="3" color="green"></font> Customer(s)</label>
<tr ng-repeat="item in $data " >
<td width="30" style="text-align: left" header="\'smsChkbx\'">
<label>
<input type="checkbox" class="ace" name="someList[]" value="" ng-model="checkboxes.items[item.somename]" />
checkbox function
$scope.$watch('checkboxes.items', function(values) {
if (!$scope.mydata) {
return;
}
var checked = 0,
unchecked = 0,
total = $scope.mydata.length;
angular.forEach($scope.mydata, function(item) {
checked += ($scope.checkboxesSms.items[item.somename]) || 0;
unchecked += (!$scope.checkboxesSms.items[item.somename]) || 0;
});
if ((unchecked == 0) || (checked == 0)) {
$scope.checkboxes.checked = (checked == total);
}
**if(checked != 0 && unchecked != 0){
$scope.checkedResult++;
}**
$scope.tableParamsSms.reload();
console.log($scope.checkedResult);
console.log((checked != 0 && unchecked != 0));
angular.element(document.getElementById("select_Sms")).prop("indeterminate", (checked != 0 && unchecked != 0));
}, true);
counts properly when i check for first time, the issue is it wlll also count when i uncheck the checked one
also want to count when its checked by multiple check option
Aucun commentaire:
Enregistrer un commentaire