0

I base in this example: http://code.ciphertrick.com/2014/12/06/highlight-a-selected-row-in-ng-repeat-using-ng-class/ Demo: http://code.ciphertrick.com/demo/ngClass/

The example is working ok, but i need to add a button element and when i click in the button, i want to show in a alert, the value of name column, for example "Noodles"

This is my code html:

<table class="table table-hover">
    <thead>
        <tr>
            <th>Branch</th>
            <th>Name</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="organizational in organizationals" ng-class="{'selected':$index == selectedRow}" ng-click="setClickedRow($index)">
      <td>{{organizational.branch}}</td>
            <td>{{organizational.name}}</td>
        </tr>
    </tbody>
</table>
<button type="button" class="btn btn-default" ng-click="createSelectRowClick();">Select</button>

This is my js code:

$scope.managers = [
 {name: 'Ana Faedo Iglesias'},
 {name: 'Cristina Menendez'},
 {name: 'Daniel Piriz'}
];

$scope.selectedRow = null;

$scope.setClickedRow = function(index){
    $scope.selectedRow = index;
}
$scope.createSelectRowClick = function(){
  if ($scope.selectedRow==null)
  {
    alert("Any rows selected");
  }
  else
  {
    //alert("valuetd" + value td column name, about click row);
  }
}

NOTE: The table is in a modal window, if i click in table row, I recover the value of the column, i close the window modal, and after, i can put the column value wherever.

How could do it? thanks,

1 Answer 1

1

Hope this will solve your problem.

$scope.createSelectRowClick = function(){
  if ($scope.selectedRow==null)
  {
    alert("Any rows selected");
  }
  else
  {
    alert("valuetd " + $scope.organizationals[$scope.selectedRow].name);
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome. Happy to know that.

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.