1
angular.module('harbinger').controller(
   'Admin.UserlistController',  
   function($rootScope, $scope, $location, $http, userService)
   {
      // etc
      $scope.gridOptions = {
         // etc ,
         enableRowSelection: false,
         columnDefs: [
            {field: 'userName', displayName: 'Username'},
            {field: 'name', displayName: 'Name'},
            {field: 'organization', displayName: 'Organization'},
            {field: 'title', displayName: 'Title'},
            {field: 'dateOfBirth', displayName: 'Date Of Birth'},   
            {field: 'controls', displayName: '', cellTemplate: '<div id="controls" ><a id="user-edit" onClick="editUser(\'{{row.entity.userName}}\')">Edit</a> | <a id="user-reset" data-ng-click="resetUser(\'{{row.entity.userName}}\')">Reset</a> | <a id="user-unlock">Un-lock</a></div>'}
         ]
      };

onclick of user reset i have to pass the

userService.reset($scope.userData, function( data ) // success
                {
                   // etc
                }

i am using ngGrid, and i am trying to call a scope method from a button displayed in ngGrid. –

on click i am not able to execute this function . Please give me angular js way to do this .

8
  • Could you please add the html code? Or better a jsfiddle? Commented Jun 28, 2013 at 10:00
  • Check your browser console for the errors! Commented Jun 28, 2013 at 10:02
  • @DadoJerry : its not showing any error,on page load it will work Commented Jun 28, 2013 at 10:03
  • @Kersten <div class="gridStyle" ng-grid="gridOptions" style="display:none"></div> Commented Jun 28, 2013 at 10:04
  • supposed to see the html that your are triggering ng-click() Commented Jun 28, 2013 at 10:04

1 Answer 1

4

Maybe it's an old question but I'll answer it.

ngGrid creates an isolated scope so there is no way of getting to your parent scope via something like this:

  1. $parent.editUser('')
  2. <div ng-controller="AppCtrl as ctrl"><div ng-grid="options"></div></div> and ctrl.editUser('')
  3. by using . ($scope.callback = {}; $scope.callback.editUser = function(){}; -> callback.editUser(''))

ngGrid uses your options in the isolated scope, which is available to your cell/rowTemplates - so you can do as follows:

Javascript Controller:

$scope.editUser = function(userName) {
    ...
};

$scope.options = {
    data: 'data',
    columnDefs: [{
        field:'name', 
        displayName:'name', 
        cellTemplate: '<div ng-click="options.editUser(\'{{row.entity.userName}}\')">Edit</div>'
    }],
    editUser: $scope.editUser
}

HTML:

<div ng-grid="options"></div>

Plunker: Test app

Sign up to request clarification or add additional context in comments.

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.