mautrok mautrok - 1 year ago 244
AngularJS Question

insert ng-click event into ng-grid

i want to do something that i don't know if it is possible


<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="utf-8">
<title>Custom Plunker</title>
<link rel="stylesheet" type="text/css" href="" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src=""></script>
<script src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src="main.js"></script>
<body ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions"></div>


// main.js
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.myData = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
$scope.gridOptions = { data: 'myData',
cellTemplate:'<div class="ngCellText" ><a ng-click="foo()">{{row.getProperty(col.field)}}</a></div>'
$ = function() {


I want to put a ng-click event on a row in a ng-grid,i have take the idea looking around, but I don't really understand if it is possible and, if it is so, if that's the right way to do that.
In this code, that seems to be good to me, the app doesn't start the alert, any suggest or ideas?

Here is the plunker

Answer Source

These definitions work for me:

  $scope.gridOptions = {
    data: 'myData',
    columnDefs: [{
        field: 'name',
        displayName: 'Name',
        cellTemplate: '<div  ng-click="foo()" ng-bind="row.getProperty(col.field)"></div>'
      }, {
        field: 'age',
        displayName: 'Age',
        cellTemplate: '<div  ng-click="foo()" ng-bind="row.getProperty(col.field)"></div>'


See your forked Plunker here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download