如何从纳克格单元格的值 [英] How to get the cell value from ng-grid

查看:122
本文介绍了如何从纳克格单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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.

这篇关于如何从纳克格单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆