UI-GRID-subgrid

In this example below you will see how to do a UI-GRID-subgrid with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by NoBine, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright NoBine ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>UI-GRID-subgrid</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  <link rel='stylesheet prefetch' href='https://ui-grid.info/release/ui-grid-unstable.css'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <html ng-app="app">
  <head>
    
    <link rel="stylesheet" href="style.css" type="text/css">
  </head>
  <body>

<div ng-controller="MainCtrl">
  
  <div ui-grid="gridOptions" ui-grid-pinning ui-grid-expandable class="grid"></div>
</div>



    <script src="script.js"></script>
  </body>
</html>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.26/angular.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.26/angular-touch.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.26/angular-animate.js'></script>
<script src='https://ui-grid.info/docs/grunt-scripts/csv.js'></script>
<script src='https://ui-grid.info/release/ui-grid-unstable.js'></script>
<script src='https://ui-grid.info/docs/grunt-scripts/vfs_fonts.js'></script>
<script src='https://ui-grid.info/docs/grunt-scripts/pdfmake.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/NoBine/ui-grid-subgrid-PQPRWz */
/* Styles go here */
.grid {
  width: 100%;
  height: 400px;
}


/*Downloaded from https://www.codeseek.co/NoBine/ui-grid-subgrid-PQPRWz */
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) {
  $scope.gridOptions = {
    expandableRowTemplate: '<div ui-grid="row.entity.subGridOptions" style="height:140px;"></div>',
    expandableRowHeight: 150,
  };

 $scope.clickMe = function(){
                   alert('hi');
                };
  $scope.gridOptions.columnDefs = [
    { name: 'id', cellTemplate:'<button class="btn primary" ng-click="grid.appScope.clickMe()">Click Me</button>'},
    { 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 = {
			  
          appScopeProvider: $scope.subGridScope,
          columnDefs: [ {name:"Id", field:"id", cellTemplate:'<button class="btn primary" ng-click="grid.appScope.clickMeSub()">Click Me</button>'},
          {name:"Name", field:"name"   
          } ],
          data: data[i].friends
        }
      }
      $scope.gridOptions.data = data;
    });
    
    $scope.subGridScope = {
      clickMeSub: function(){
        alert('hi there');
      }
    };

    $scope.gridOptions.onRegisterApi = function(gridApi){
      $scope.gridApi = gridApi;
    };

}]);

Comments