var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.expandable', 'ui.grid.selection', 'ui.grid.pinning']);
app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
var main = $scope;
$scope.name = 'MainCtrl';
$scope.mainData = [];
$scope.subGridOptions =
{
columnDefs: [ {name:"Id", field:"id"},{name:"Name", field:"name"} ]
};
$scope.expandableGridOptions =
{
subGridOptions : $scope.subGridOptions
};
$scope.gridOptions = {
expandableRowTemplate: 'expandableRowTemplate.html',
//expandableRowHeight: 150,
//subGridVariable will be available in subGrid scope
expandableRowScope: { subGridOptionsModel : $scope.subGridOptions }
}
$scope.gridOptions.columnDefs = [
{ name: 'id' },
{ name: 'name'},
{ name: 'age'},
{ name: 'address.city'}
];
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
/*for(i = 0; i < data.length; i++){
data[i].subGridOptions = {
columnDefs: [ {name:"Id", field:"id"},{name:"Name", field:"name"} ],
data: data[i].friends
}
}*/
$scope.gridOptions.data = data;
$scope.mainData = data;
});
$scope.gridOptions.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
//debugger;
if (row.isExpanded) {
//row.entity.subGridOptions = main.subGridOptions;
//row.entity.subGridOptions = row.entity.subGridOptions;
//row.entity.subGridOptions.data = row.entity.friends;
//main.subGridOptions.data = row.entity.friends;
/*row.entity.subGridOptions = {
columnDefs: [
{ name: 'name'},
{ name: 'gender'},
{ name: 'company'}
]};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.success(function(data) {
row.entity.subGridOptions.data = data;
});*/
}
});
};
$scope.expandAllRows = function() {
$scope.gridApi.expandable.expandAllRows();
}
$scope.collapseAllRows = function() {
$scope.gridApi.expandable.collapseAllRows();
}
}]);
app.controller('SecondCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
$scope.name = 'SecondCtrl';
$scope.gridOptions = {
enableRowSelection: true,
expandableRowTemplate: 'expandableRowTemplate.html',
//expandableRowHeight: 150
}
$scope.gridOptions.columnDefs = [
{ name: 'id', pinnedLeft:true },
{ name: 'name'},
{ name: 'age'},
{ name: 'address.city'}
];
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
for(i = 0; i < data.length; i++){
data[i].subGridOptions = {
columnDefs: [ {name:"Id", field:"id"},{name:"Name", field:"name"} ],
data: data[i].friends
}
}
$scope.gridOptions.data = data;
});
}]);
app.controller('ThirdCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
$scope.name = 'SecondCtrl';
$scope.gridOptions = {
expandableRowTemplate: 'expandableRowTemplate.html',
expandableRowHeight: 150,
onRegisterApi: function (gridApi) {
gridApi.selection.on.rowSelectionChanged(context.Private.Scope, function (row, event) {
if (event.target.localName != 'i' && event.target.localName != 'a' && context.Private.gridApi.expandable != undefined)
context.Private.gridApi.expandable.toggleRowExpansion(row.entity);
});
gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
if (row.isExpanded) {
//debugger;
row.entity.subGridOptions = {
columnDefs: [
{ name: 'name'},
{ name: 'gender'},
{ name: 'company'}
]};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.success(function(data) {
row.entity.subGridOptions.data = data;
});
}
});
}
}
$scope.gridOptions.columnDefs = [
{ name: 'id', pinnedLeft:true },
{ name: 'name'},
{ name: 'age'},
{ name: 'address.city'}
];
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
$scope.gridOptions.data = data;
});
}]);
.grid {
width: 100%;
height: 400px;
}
<div>
<div>
Name : {{row.entity.registered}} Active : {{row.entity.isActive}}
</div>
<div>
<!-- About : {{row.entity.about}} -->
</div>
<div ui-grid="subGridOptionsModel" style="height:140px;"></div>
</div>
<!doctype html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular-touch.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular-animate.js"></script>
<script src="http://localhost:9003/docs/grunt-scripts/csv.js"></script>
<script src="http://localhost:9003/docs/grunt-scripts/pdfmake.js"></script>
<script src="http://localhost:9003/docs/grunt-scripts/vfs_fonts.js"></script>
<script src="https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/release/3.0.0-rc.19/ui-grid.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/release/3.0.0-rc.19/ui-grid.css" type="text/css">
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div ng-controller="MainCtrl">
<div class="control-group">
<input type="button" class="btn btn-small" ng-click="expandAllRows()" value="Expand All"/>
<input type="button" class="btn btn-small" ng-click="collapseAllRows()" value="Collapse All"/>
</div>
<div ui-grid="gridOptions" ui-grid-pinning ui-grid-expandable class="grid"></div>
</div>
Expandable rows works with checkboxes from selection and left pins
<div ng-controller="SecondCtrl">
<div ui-grid="gridOptions" ui-grid-pinning ui-grid-expandable ui-grid-selection class="grid"></div>
</div>
Retrieve data for subGrid when expanding
<!-- <div ng-controller="ThirdCtrl">
<div ui-grid="gridOptions" ui-grid-expandable class="grid"></div>
</div> -->
<script src="app.js"></script>
</body>
</html>