I would like to create a custom column with a link and call $scope method on ng-click. There is very similar question for ngGrid (How to call a scope method from a button displayed in ngGrid -in Angular js) and that solution works. I'm using the ui-grid, which is supposed to be just a newer version of ngGrid, but it doesn't seem to work there.
Here is my code:
var app = angular.module('plunker', ['ui.grid']);
app.controller('MainCtrl', function($scope) {
$scope.gridOptions = {
data: [{name: 'test'}],
columnDefs: [{
field:'name',
displayName:'name',
cellTemplate: '<div ng-click="gridOptions.editUser()">Edit</div>'
}],
editUser: $scope.editUser
};
$scope.editUser = function() {
alert('It works!');
};
});
http://plnkr.co/edit/Q5SuIeAPFpZaUKbmIDCn
Here is the original solution for ngGrid that works: http://plnkr.co/edit/hgTQ1XdEVRyxscoNs76q
AngularJS ScopeThe scope is the binding part between the HTML (view) and the JavaScript (controller). The scope is an object with the available properties and methods. The scope is available for both the view and the controller.
$scope is a child object that is used to bind the HTML(view) & Javascript(Controller) in a webpage. It is created with the ng-app directive. It is created with the ng-controller directive. It is available globally for all the controllers, i.e, the property assigned with “$rootscope” can be used anywhere.
UI-Grid 3.0 (formerly ng-grid) is a 100% Angular grid written with no dependencies other than AngularJS. It is designed around a core grid module and features are layered as Angular modules and Directives. This keeps the core; small and focused, while executing very complex features only when you need them.
In new version of ui-grid this approach does not work for me. instead i have use appScope core api. http://ui-grid.info/docs/#/tutorial/305_appScope
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With