如何从纳克格单元格的值
我是AngularJS的初学者。我研究NG-电网的演示,并有一个问题。
I am a beginner of AngularJS. I study the demo of ng-grid and have a question.
index.html的
index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<script type="text/javascript" src="http://angular-ui.github.com/ng-grid/lib/ng-grid.debug.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions"></div>
<div class="selectedItems">{{mySelections}}</div><br><br>
</body>
</html>
app.js
app.js
var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
$scope.mySelections = [];
$scope.myData = [{name: "Moroni", id: 1},
{name: "Tiancum", id: 2},
{name: "Jacob", id: 3},
{name: "Nephi", id: 4},
{name: "Akon", id: 5},
{name: "Enos", id: 6}];
$scope.gridOptions = {
data: 'myData',
selectedItems: $scope.mySelections,
multiSelect: true
};
//$scope.mySelections_id = $scope.mySelections.length;
});
当我选择第一行,selectedItems的DIV将显示[{名:莫罗尼,标识:1}]。结果是OK。如果我只是想从选定的行单元格[ID]的值,我怎么修改我的code?
When I select the first row, the div of selectedItems will show [{"name":"Moroni","id":1}]. the result is OK. If I just want to get the value of cell [id] from selected row, how do I modify my code?
这里是 Plunker
NOTE:事实上,我希望得到一个单元格的值和修改,当用户选择在表中的单元格。
Acutally, I want to get a cell value and modify when user selects the cell at the table.
以上答案是使用固定列的申请..喜欢
Above answers are using fixed columns's filed.. like
$scope.selectedIDs.push( item.id ) // id is column filed
而不是回答这些问题,我发现我想要实现与正是另一种方式。
Instead of these answers, I found another way exactly what I want to achieve with.
举例code:
http://plnkr.co/edit/wfiMhlJ7by4eUHojjKT4?p=$p$pview一>
editableCellTemplate
这是一个选项, columnDefs
用于解决这一问题。
editableCellTemplate
which is an option for columnDefs
is used for solving this problem.