0

I have a table with check box for each row .

I need to remove the rows for the selected check boxes in the table on a button click. (this button is outside ng-repeat).

The index of the selected rows are populated to an array using ng-change function but i'm unable to remove the selected rows on a single button click

Here is the Fiddle

HTML

<div ng-app="approvalApp">
<div ng-controller="SimpleApprovalController" >
<table style="width:90%" border="5"  >
<tr>   
    <th><input type="checkbox" ng-model="CheckAllData" ng-    change="selectAll()" /></th>
    <th>Date</th>
   <th>AssociateID</th>   
<th>Check-In</th>
<th>Checkout</th> 
</tr>

<tr data-ng-repeat="approval in approvalitems">     
    <td><input type="checkbox" value="{{approval.ReqId}}" data-ng-model="approval.selected" data-ng-change="SelectDeselect($index)"/></td>
<td>{{approval.Date}}</td>
<td>{{approval.AssociateID}}</td>
<td>{{approval.CheckIn}}</td>
<td>{{approval.Checkout}}</td>

</tr>
</table>
<input type="button" value="Approve" data-ng-model="ApproveIndex" data-ng-click="ApproveRequest()" />

Script

    $scope.SelectDeselect=function(index)
    {
        $scope.getIndexvalues = [];
        angular.forEach($scope.approvalitems, function (approval,index) {               
            if (!!approval.selected) {
               $scope.getIndexvalues.push(index);
                $scope.CheckAllData = false;                 
            }              
        });

        console.log($scope.getIndexvalues);
    };

$scope.ApproveRequest = function () {           
        $scope.selectedIdsArray = [{}];          
        angular.forEach($scope.approvalitems, function (item) {                
            if (!!item.selected) { 
                $scope.selectedIdsArray.push({ Reqid: item.ReqId, Status: "Approved" });
                $scope.CheckAllData = false; 
            }               
        });           

    };
};

So how to use getIndexvalues in approverequest function , or is there any better way to remove it using other angular directive. I'm a newbie to angular js .

2 Answers 2

1

Fiddle: http://jsfiddle.net/jpk547zp/1/

$scope.ApproveRequest = function () {
    $scope.selectedIdsArray = [{}];
    $scope.approvalitemsNew = [];
    angular.forEach($scope.approvalitems, function (item) {
        if (!!item.selected) {
            $scope.selectedIdsArray.push({ Reqid: item.Date, Status: "Approved" });
            $scope.CheckAllData = false;
            item.hideThis = true;
            console.log($scope.selectedIdsArray);
        } else {
            $scope.approvalitemsNew.push(item);
        }
    });
    $scope.approvalitems = $scope.approvalitemsNew;
    $scope.getIndexvalues = [];
};

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

you can simply do

$scope.ApproveRequest = function () {           
  $scope.approvalitems = $scope.approvalitems.filter(function(i){
      return !i.selected;
  });
};

4 Comments

Thank you , but i need to remove the selected rows on the approve button click rather than the checkbox click.
then do the same thing on button's ng-click
but there is only one button present and its outside ng-repeat. Its like many rows with one button at the bottom of the table.
Thanks for the simple and effective approach. Unable to up vote now due to less score,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.