How do I create (or access) an array of selected rows in my 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.
<body ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions"></div>
<h3>Rows selected</h3>
<pre>{{selectedItems}}</pre>
</body>
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)
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>
You can get selected items of ng-grid 2.x from:
$scope.gridOptions.$gridScope.selectedItems
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With