我有一个UI网格,我想点击单元格值。
这是我的代码
user.js的
var app = angular.module("myApp");
app.controller("userController", function ($scope) {
$scope.number;
var myData = [{
"firstName": "Cox",
"lastName": "Carney",
"company": "Enormo",
"employed": true
}, {
"firstName": "Lorraine",
"lastName": "Wise",
"company": "Comveyer",
"employed": false
}, {
"firstName": "Nancy",
"lastName": "Waters",
"company": "Fuelton",
"employed": false
},
{
"firstName": "Priyanka",
"lastName": "Taneja",
"company": "GE",
"employed": true
},
{
"firstName": "Ashish",
"lastName": "Grover",
"company": "Deloitte",
"employed": true
}
];
$scope.count = function () {
$scope.number = 3;
}
$scope.gridOptions = {
enableColumnMenus: false,
enableSorting: true,
columnDefs: [
{
name: 'firstName',
width: "25%",
displayName: 'FirstName(' +
$scope.number + ')',
cellTemplate: '<div ng-click="grid.appScope.count()" ng-bind="row.entity.firstName"></div>'
},
{
name: 'lastName',
width: "25%",
displayName: 'LastName'
},
{
name: 'company',
width: "25%",
displayName: 'Company'
},
{
name: 'employed',
width: "25%",
displayName: 'Employed'
}
]
}
$scope.gridOptions.data = myData;
});
<div ng-app="myApp" ng-controller="userController">
<div ui-grid="gridOptions" class="grid"></div>
我想点击单元格。并且我希望值的值与FirstName一起显示,其中值为undefined。我该如何解决这个问题。
答案 0 :(得分:0)
displayName: 'FirstName(' +
$scope.number + ')',
到
displayName: 'FirstName({{number}})',
答案 1 :(得分:0)
您永远不会设置$scope.number;
的值。当网格加载时,它会在那里查找某些内容,并且它未定义。
尝试这样的事情:
displayName: 'FirstName' + ($scope.number ? '(' + $scope.number + ')' : ''),
使用三元运算符。基本上它说&#34;如果定义$ scope.number,则显示它(连同括号),否则,只显示 FirstName 。