Get Selected Rows Data Angularjs ng-grid

Get Selected Rows Data Angularjs ng-grid

If you are using Angularjs ng-grid to show the data and want to find what rows user has selected including capture its all or particular cell field data you could use below:

  • HTML page:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>Test</title>
<link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" />
<style type="text/css">
	.gridStyle {
		border: 1px solid rgb(212,212,212);
		width: 400px; 
		height: 150px
	}
	.selectedItems{
		float: left; 
	}
</style>
<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>
	
	var app = angular.module('myApp', ['ngGrid']);
	app.controller('MyCtrl', function($scope) {
	$scope.mySelections = [];
	$scope.myData = [{name: "Test1", id: 1},
					 {name: "Test2", id: 2},
					 {name: "Test3", id: 3}];
	$scope.gridOptions = { 
	data: 'myData',
	selectedItems: $scope.mySelections,
	multiSelect: true 
	};	
	
	});
</script>
</head>
 
<body ng-controller="MyCtrl">
	<p><b>First Grid</b></p>
    <div class="gridStyle" ng-grid="gridOptions" data-ng-click="testSeletion()"></div>
	<p><b>Selected rows:</b></p>
	<div class="selectedItems">{{mySelections}}</div><br><br>
	
</body>
</html>
  • Output:

Get Selected Rows Data Angularjs ng-grid

Test this code in Plunker here

Leave a Reply

Your email address will not be published. Required fields are marked *