从ng-grid获取选择的行?

Foo*_*ack 12 data-binding angularjs angularjs-directive angularjs-scope ng-grid

如何在ng-grid中创建(或访问)所选行的数组?


文档(滚动到"网格选项")

id                 | default value | definition
-----------------------------------------------
selectedItems      |       []      | all of the items selected in the grid.
                                     In single select mode there will only
                                     be one item in the array.
Run Code Online (Sandbox Code Playgroud)

的index.html

<body ng-controller="MyCtrl">
    <div class="gridStyle" ng-grid="gridOptions"></div>

    <h3>Rows selected</h3>
    <pre>{{selectedItems}}</pre>
</body>
Run Code Online (Sandbox Code Playgroud)

main.js

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope) {
    $scope.myData = [{name: "Moroni", age: 50},
                     {name: "Tiancum", age: 43},
                     {name: "Jacob", age: 27},
                     {name: "Nephi", age: 29},
                     {name: "Enos", age: 34}];
    $scope.gridOptions = { data: 'myData' };
});
Run Code Online (Sandbox Code Playgroud)

代码的Plnkr(并运行它)

Ye *_*Liu 23

基于doc,selectedItems应该是属性$scope.gridOptions,所以试试这个:

调节器

$scope.gridOptions = { data: 'myData', selectedItems: [] };
Run Code Online (Sandbox Code Playgroud)

HTML

<pre>{{gridOptions.selectedItems}}</pre>
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,原以为这是默认选项; 由于它具有默认值; 我想我再也不会想到了.它的工作:) (2认同)

Tha*_*hHH 7

您可以从以下位置获取ng-grid 2.x的选定项目:

$scope.gridOptions.$gridScope.selectedItems
Run Code Online (Sandbox Code Playgroud)