Question

I am using cell template property of ng-grid. I am defining one function in the directive. Within the same directive I am defining my grid-options. Here is the code:

data: 'mydata',
columnDefs: [

{field:'Timeout', displayName:'Delay', cellTemplate: '<a href="" 
ng-click= "Report(Alert,Key,1000,1,1);"><div class=\"ngCellText\">{{row.getProperty(col.field)}}</div></a>'}   
        ]

and function Report is also defined within same directive.

ng-click is working whenever it gets clicked. The function is getting called but whatever the input variable I am passing (Alert and Key) is not passing to the function whereas the rest three parameters 1000,1,1 are getting passed. Alert is the hard-coded string what I wants to pass. Key is one of the array of integer values in 'mydata'. I checked by using alert for these 2 specific values in function and it is showing UNDEFINED.

Please help in calling the function correctly. Thanks in advance.

Was it helpful?

Solution

Do you want something like this:

  $scope.Report=function(msg,key,v1,v2,v3){
    //use v1, v2, v3 for whatever you like
    alert(msg+':'+key);
  };

  $scope.gridOptions = {
    data: 'myData',
    columnDefs: [
      {
        field: 'name',
        displayName: 'Delay',
        cellTemplate: '<a href="" ng-click= "Report(\'Alert\',row.entity.age,1000,1,1);"><div class=\"ngCellText\">{{row.getProperty(col.field)}}</div></a>'
      }, {
        field: 'age'
      }
    ]
  };

Note that the hardcoded string (msg) must be put in escaped quotes. I used age as example for a key. Since its a numeric value in this example, you don't need the quotes.

Here is a Plunker

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top