2016-08-23 7 views
0

확인란을 선택하면 테이블에서 일부 행을 숨기는 테이블이 있습니다. 처음에는 미리 계산 한 값을 보여줍니다. 행을 숨기거나 표시하기 위해 ng-show를 사용하고 있습니다. 따라서 길이 함수는 여전히 총 ​​카운트를 반환합니다.ng-show/hide/if에 의해 숨겨진 행 수 계산

<input type="checkbox" ng-model="isRChecked" id="chck3" ng-change="ExcludeRChecked();"><label for="chck3">Exclude R</label> 


<div>{{Detail.length}} Rows in Table</div> 
<tbody> 
    <tr ng-repeat="x in Detail" ng-show="excludeR(x.ID)"> 
    <td colspan="1">{{x.feature}}</td> 
    <td colspan="1" ng-click="test(x.ID)">{{x.ID}}</td> 
    <td colspan="1">{{x.Log}}</td> 
    </tr> 
</tbody> 

테이블의 행 수를 표시해야합니다. 따라서 확인란을 선택하면 ng-show의 숨겨진 행 수를 제거해야합니다.

각도 기능 ExcludeR() 컨트롤러의 프리 필터 Detail

$scope.excludeR=function(item){ 
      if($scope.isRChecked===false) 
       return true; 
       for(x in $scope.R){ 
        if($scope.R[x]===item) 
        {       
         return false; 
        } 
       } 
       return true; 

     }; 
+0

당신은 또한 당신의 체크 박스 코드를 추가 할 수 있습니까? –

답변

0

$scope.filteredDetail = $scope.Detail.filter(x => excludeR(x.ID)) 

<div>{{filteredDetail.length}} Rows in Table</div> 
<tbody> 
    <tr ng-repeat="x in filteredDetails track by x.ID "> 
    <td colspan="1">{{x.feature}}</td> 
    <td colspan="1" ng-click="test(x.ID)">{{x.ID}}</td> 
    <td colspan="1">{{x.Log}}</td> 
    </tr> 
</tbody> 
1
<div>{{visibleDetailsCount}} Rows in Table</div> 
<tbody> 
    <tr ng-repeat="x in Detail" ng-show="excludeR(x.ID)"> 


$scope.excludeR(param){ 
    //... 
    condition?$scope.visibleDetailsCount++:$scope.visibleDetailsCount--; 
    //... 
} 
+0

ng-repeat에는 fn을 사용할 수 없습니다. 무한 루프에서 멈추다 – matrixguy