Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  1] [ 1]  / answers: 1 / hits: 20017  / 11 Years ago, wed, november 6, 2013, 12:00:00

How does one pass {{row.getProperty(col.field)}} into ng-click? What happens is the id does not get propagated back, but the grid render correctly with the id.



code:



var app = angular.module('testing',['ngGrid']);
app.config(['$locationProvider', function($locationProvider)
{
$locationProvider.html5Mode(true);
}]);

app.controller('TestCtrl',function($scope)
{
$scope.details = []; //whatever dummy data
$scope.loadById = function(id)
{
$window.location.href= 'newPage/?id='+id;
};

$scope.gridOptions =
{
data: 'details',
columnDefs:[{field:'id',DisplayName:'id',
cellTemplate:'<div class=ngCellText ng-class=col.colIndex()><a ng-click=loadById({{row.getProperty(col.field)}})>{{row.getProperty(col.field)}}</a></div>'
}]
};
});

More From » angularjs

 Answers
1

You can just pass row in ng-click, instead of only the value outputted by the double brackets expression.



Your cellTemplate becomes this



cellTemplate:'<div class=ngCellText ng-class=col.colIndex()><a ng-click=loadById(row)>{{row.getProperty(col.field)}}</a></div>' 


Your function becomes this



$scope.loadById = function(row) {  
window.console && console.log(row.entity);
$window.location.href= 'newPage/?id='+ row.entity.id;
};

[#74457] Tuesday, November 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;