Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I create (or access) an array of selected rows in my ng-grid?


Documentation (scroll to "Grid options")

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.

index.html

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

    <h3>Rows selected</h3>
    <pre>{{selectedItems}}</pre>
</body>

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' };
});

Plnkr for the code (and to run it)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
868 views
Welcome To Ask or Share your Answers For Others

1 Answer

Based on the doc, selectedItems should be a property of $scope.gridOptions, so try this:

Controller

$scope.gridOptions = { data: 'myData', selectedItems: [] };

HTML

<pre>{{gridOptions.selectedItems}}</pre>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...