stackover flow
stackover flow

Reputation: 81

How to get the row value from ng-grid in angular js

How can I get a row value, when click cell in ng-grid?

example:

Name   Number  Class

X      123      A

Y      234      B

Z      345      C

A      456      D

When click on 123 cell or A cell or X cell, how can i get value X.

Please any help me. thanks in Advance

Upvotes: 1

Views: 2446

Answers (2)

Pankaj Parkar
Pankaj Parkar

Reputation: 136184

You should write ng-click of cellTemplate ng-click="clicked(row)"

Controller

$scope.clicked = function(row){
   alert(row.getProperty("Name"));
};

Upvotes: 0

Brett DeWoody
Brett DeWoody

Reputation: 62881

One option - add an ng-click function on each row that returns the value in the first column.

HTML

<tr ng-repeat="item in items" ng-click="getVal(item)">
  <td>{{item.name}}</td>
  <td>{{item.number}}</td>
  <td>{{item.class}}</td>
</tr>

Controller

$scope.getVal = function(item) {
    alert(item.name);
}

Here's a working demo.

Upvotes: 0

Related Questions