1

I am having a list in angular js with many rows . I wanted to select multiple rowsin the list and add it to another table .

My code is

<li class = "list-group-item listroleitem" ng-repeat='role in roles' ng-click="selectRow(role)
          " ng-class="{selectedRole: role === idSelectedRow}">{{role.roleName}}</li>

Controller :

$scope.selectRow = function(name){
        $scope.idSelectedRow = name;

    };

how to do it ?

2 Answers 2

1

Since you control the selected rows variable, why not initialise it as an array?

$scope.idSelectedRow = [];

$scope.selectRow = function(name){
     if( $scope.idSelectedRow.indexOf(name) > -1 )
        $scope.idSelectedRow.splice($scope.idSelectedRow.indexOf(name), 1);
     else
        $scope.idSelectedRow.push( name );

};

And then use this in css:

<li class = "list-group-item listroleitem" ng-repeat='role in roles' ng-click="selectRow(role)
          " ng-class="{selectedRole: isSelected( role ) }">{{role.roleName}}</li>




$scope.isSelected = function(some_role){
          return $scope.idSelectedRow.indexOf(role) >-1;
}
Sign up to request clarification or add additional context in comments.

1 Comment

How would i deselect ?
0

Change your code to

<li class = "list-group-item listroleitem" ng-repeat='role in roles' ng-click="selectRow(role)
        " ng-class="{selectedRole: role.selected==true}">{{role.roleName}}---{{role.selected}}</li>

function TodoCtrl($scope) {
    $scope.roles = [{roleName:"abc"}, {roleName:"dc"}]
    $scope.name = 'Superhero';

    $scope.selectRow = function(role){
        role.selected = !role.selected;
    };
}

https://jsfiddle.net/U3pVM/30783/

Comments

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.