lundi 27 juillet 2015

How to use checkbox filter in angularjs?

I want to check checkbox based on selection. Suppose in this example i have four logical operation want to do in dynamically.

  1. If Show All selected(checked) remaining all need to select automatically.

  2. If Show All unchecked i have to remove all checked to unchecked.
    If Show Activated & Show In

  3. Activated selected(checked) - Show All should automatically get select.

  4. If any one removed(unchecked - either show activated or show in activated) - Show All should automatically get deselect.

Note : by default show all selected

Here the source code attached.

$scope.objectTypes = ['Show Activated', 'Show InActivated', 'Show All'];    
$scope.selected = ['Show All'];   
$scope.objectSelection = function objectSelection(objectType) {
         var idx = $scope.selected.indexOf(objectType);  


          // is currently selected
         for(var i=0; i<$scope.objectTypes.length;i++) {
         if (idx > -1) {
                if($scope.objectTypes[i]==objectType) {
                      $scope.selected.splice(idx, 1);
                      $scope.selected.splice(1, 1); 
                  }          
         }       
         else if($scope.selected!=0) {      
                if($scope.objectTypes[i]==$scope.selected) {
                      $scope.selected.push(objectType);
                      if(!$scope.selected["Show All"])
                      $scope.selected.push("Show All");
                }            
           } 
          else {
              $scope.selected.push(objectType);
              break;
           }
         }
    };

any one please help me to achieve this in angularjs.




Aucun commentaire:

Enregistrer un commentaire