<!DOCTYPE html>
<html>

<head>
  <link data-require="bootstrap-css@3.0.1" data-semver="3.0.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css" />
  <script data-require="jquery@2.2.0" data-semver="2.2.0" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  <script data-require="bootstrap@3.0.1" data-semver="3.0.1" src="//netdna.bootstrapcdn.com/bootstrap/3.0.1/js/bootstrap.min.js"></script>
  <script data-require="angular.js@1.5.7" data-semver="1.5.7" src="https://code.angularjs.org/1.5.7/angular.js"></script>
  <script data-require="ag-grid@5.0.6" data-semver="5.0.6" src="https://rawgit.com/ceolter/ag-grid/master/dist/ag-grid.js"></script>

  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>



<body>
  <div class="container" ng-app="tableapp" ng-controller="tableController as tc">
    <div class="row">
      <div style="width: 100%; height: 400px;" ag-grid="tc.gridOptions" class="ag-fresh"></div>
    </div>
  </div>
  
  <style>
  .ag-header-cell-label {
    justify-content: center;
  }
</style>
</body>

</html>
agGrid.initialiseAgGridWithAngular1(angular);

var app2 = angular.module('tableapp', ['agGrid']);

var tableController = function ($scope, $q, $filter, $document) {

    var self = this;

    this.data = [];
    this.gridOptions = {};

    //all table columns
    this.tableColumns = [
        //{ colId: 0, field: 'flightId', displayName: 'flight ID', minWith: 20, width: 100, visible: false, cellClass: self.cellClass, cellTemplate: '/Templates/gridcelltemplate.html' },
        { colId: 1, field: 'registrationId', headerName: 'reg.' },
        { colId: 2, field: 'flight', headerName: 'Flight'},
        { colId: 3, field: 'type', headerName: 'type'},
    ];

    this.init = function () {

        self.data = self.builddata();
        self.gridOptions = {
            rowData: self.data,
            //virtualizationThreshold: self.data.length,//this could turn off the lazy loading, but makes it very slow.
            columnDefs: self.tableColumns,
            enableColResize: true,
            rowSelection: 'single',
          
            onCellFocused : function(params){
              console.log(params);
                if (params && params.forceBrowserFocus) {
                var row = self.gridOptions.api.getModel().getRow(params.rowIndex);
                row.setSelected(true);
              }
            }
        };
   
    };

 
    //temporary to build fake data
    this.builddata = function () {
        var someData = [];
        for (var i = 0; i < 10; i++) {
            var item = {};
            for (var x in self.tableColumns) {
                item[self.tableColumns[x].field] = x + i + "randomdata";
            }
            someData.push(item);
        }
        setInterval(function(){
          var item = {};
            for (var x in self.tableColumns) {
                item[self.tableColumns[x].field] = x + i + "randomdata";
            }
            self.data.push(item);
            self.gridOptions.api.setRowData(self.data);
        },1000)
        return someData;
    }


    self.init();
};
angular.module('tableapp').controller('tableController', ['$scope', '$q', '$filter', '$document', tableController]);
ag-grid-ng2 {
  display: inline-block;
}
.ag-select-agg-func-popup {
  position: absolute;
}
.ag-body-no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.ag-root {
/* set to relative, so absolute popups appear relative to this */
  position: relative;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
/* was getting some 'should be there' scrolls, this sorts it out */
  overflow: hidden;
}
.ag-font-style {
  cursor: default;
/* disable user mouse selection */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.ag-no-scrolls {
  white-space: nowrap;
  display: inline-block;
}
.ag-scrolls {
  height: 100%;
}
.ag-popup-backdrop {
  position: fixed;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
}
.ag-header {
  position: absolute;
  top: 0px;
  left: 0px;
  white-space: nowrap;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  width: 100%;
}
.ag-pinned-left-header {
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  overflow: hidden;
  height: 100%;
}
.ag-pinned-right-header {
  float: right;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  overflow: hidden;
  height: 100%;
}
.ag-header-viewport {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  height: 100%;
}
.ag-scrolls .ag-header-row {
  position: absolute;
}
.ag-scrolls .ag-header-container {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
  white-space: nowrap;
  height: 100%;
}
.ag-no-scrolls .ag-header-container {
  white-space: nowrap;
}
.ag-header-overlay {
  display: block;
  position: absolute;
}
.ag-header-cell {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  vertical-align: bottom;
  text-align: center;
  display: inline-block;
  height: 100%;
  position: absolute;
}
.ag-dnd-ghost {
  font-size: 14px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  position: absolute;
  background: #e5e5e5;
  border: 1px solid #000;
  cursor: move;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  padding: 3px;
  line-height: 1.4;
}
.ag-dnd-ghost-icon {
  display: inline-block;
  float: left;
  padding-left: 2px;
  padding-right: 2px;
}
.ag-dnd-ghost-label {
  display: inline-block;
}
.ag-header-group-cell {
  height: 100%;
  display: inline-block;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
  position: absolute;
}
.ag-header-group-cell-label {
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
}
.ag-header-cell-label {
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
}
.ag-header-cell-resize {
  height: 100%;
  width: 4px;
  float: right;
  cursor: col-resize;
}
.ag-header-expand-icon {
  padding-left: 4px;
}
.ag-header-cell-menu-button {
  float: right;
}
.ag-overlay-panel {
  display: table;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.ag-overlay-wrapper {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}
.ag-body {
  height: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.ag-floating-top {
  position: absolute;
  left: 0px;
  width: 100%;
  white-space: nowrap;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
}
.ag-pinned-left-floating-top {
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  overflow: hidden;
  height: 100%;
}
.ag-pinned-right-floating-top {
  float: right;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  overflow: hidden;
  height: 100%;
}
.ag-floating-top-viewport {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  height: 100%;
}
.ag-floating-top-container {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
  white-space: nowrap;
}
.ag-floating-bottom {
  position: absolute;
  left: 0px;
  width: 100%;
  white-space: nowrap;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
}
.ag-pinned-left-floating-bottom {
  float: left;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  overflow: hidden;
  height: 100%;
}
.ag-pinned-right-floating-bottom {
  float: right;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  overflow: hidden;
  height: 100%;
}
.ag-floating-bottom-viewport {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  height: 100%;
}
.ag-floating-bottom-container {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
  white-space: nowrap;
}
.ag-pinned-left-cols-viewport {
  float: left;
  overflow: hidden;
}
.ag-pinned-left-cols-container {
  display: inline-block;
  position: relative;
}
.ag-pinned-right-cols-viewport {
  float: right;
  overflow-x: hidden;
  overflow-y: auto;
}
.ag-pinned-right-cols-container {
  display: inline-block;
  position: relative;
}
.ag-body-viewport-wrapper {
  height: 100%;
}
.ag-body-viewport {
  overflow-x: auto;
  overflow-y: auto;
  height: 100%;
}
.ag-scrolls .ag-body-container {
  position: relative;
  display: inline-block;
}
.ag-scrolls .ag-row {
  white-space: nowrap;
  position: absolute;
  width: 100%;
}
.ag-no-scrolls .ag-row {
  position: relative;
}
.agile-gird-row:hover {
  background-color: #f0f8ff;
}
.ag-column-drop {
  width: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.ag-column-drop-vertical .ag-column-drop-cell {
  display: block;
}
.ag-column-drop-vertical .ag-column-drop-empty-message {
  display: block;
}
.ag-column-drop-vertical .ag-column-drop-cell-button {
  float: right;
  line-height: 16px;
}
.ag-column-drop-horizontal {
  white-space: nowrap;
}
.ag-cell {
  display: inline-block;
  white-space: nowrap;
  height: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
  position: absolute;
}
.ag-fade-out {
  opacity: 1;
  -ms-filter: none;
  filter: none;
  margin-right: 5px;
  -webkit-transition: opacity 3s, margin-right 3s;
  -moz-transition: opacity 3s, margin-right 3s;
  -o-transition: opacity 3s, margin-right 3s;
  -ms-transition: opacity 3s, margin-right 3s;
  transition: opacity 3s, margin-right 3s;
  -webkit-transition-timing-function: linear;
  -moz-transition-timing-function: linear;
  -o-transition-timing-function: linear;
  -ms-transition-timing-function: linear;
  transition-timing-function: linear;
}
.ag-fade-out-end {
  opacity: 0;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
  filter: alpha(opacity=0);
  margin-right: 10px;
}
.ag-cell-edit-input {
  width: 100%;
  height: 100%;
}
.ag-group-cell-entire-row {
  width: 100%;
  display: inline-block;
  white-space: nowrap;
  height: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
}
.ag-footer-cell-entire-row {
  width: 100%;
  display: inline-block;
  white-space: nowrap;
  height: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
}
.ag-large .ag-root {
  font-size: 20px;
}
.ag-popup-editor {
  position: absolute;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.ag-menu {
  position: absolute;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.ag-menu-column-select-wrapper {
  width: 200px;
  height: 300px;
  overflow: auto;
}
.ag-menu-list {
  display: table;
  border-collapse: collapse;
}
.ag-menu-option {
  display: table-row;
}
.ag-menu-option-text {
  display: table-cell;
}
.ag-menu-option-shortcut {
  display: table-cell;
}
.ag-menu-option-icon {
  display: table-cell;
}
.ag-menu-option-popup-pointer {
  display: table-cell;
}
.ag-menu-separator {
  display: table-row;
}
.ag-menu-separator-cell {
  display: table-cell;
}
.ag-virtual-list-viewport {
  overflow-x: auto;
  height: 100%;
  width: 100%;
}
.ag-virtual-list-container {
  position: relative;
  overflow: hidden;
}
.ag-rich-select {
  outline: none;
}
.ag-rich-select-list {
  width: 200px;
  height: 200px;
}
.ag-set-filter-list {
  width: 200px;
  height: 200px;
}
.ag-set-filter-item {
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.ag-virtual-list-item {
  position: absolute;
  width: 100%;
}
.ag-filter-filter {
  width: 170px;
  margin: 4px;
}
.ag-filter-select {
  width: 110px;
  margin: 4px 4px 0px 4px;
}
.ag-no-vertical-scroll .ag-scrolls {
  height: unset;
}
.ag-no-vertical-scroll .ag-body {
  height: unset;
}
.ag-no-vertical-scroll .ag-body-viewport-wrapper {
  height: unset;
}
.ag-no-vertical-scroll .ag-body-viewport {
  height: unset;
}
.ag-list-selection {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor: default;
}
.ag-tool-panel {
  width: 200px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor: default;
  height: 100%;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  overflow: auto;
}
.ag-column-select-indent {
  display: inline-block;
}
.ag-column-select-column {
  margin-left: 14px;
  white-space: nowrap;
}
.ag-column-select-column-group {
  white-space: nowrap;
}
.ag-hidden {
  display: none;
}
.ag-faded {
  opacity: 0.3;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
  filter: alpha(opacity=30);
}
.ag-width-half {
  width: 50%;
  display: inline-block;
}
.ag-shake-left-to-right {
  -webkit-animation-name: ag-shake-left-to-right;
  -moz-animation-name: ag-shake-left-to-right;
  -o-animation-name: ag-shake-left-to-right;
  -ms-animation-name: ag-shake-left-to-right;
  animation-name: ag-shake-left-to-right;
  -webkit-animation-duration: 0.2s;
  -moz-animation-duration: 0.2s;
  -o-animation-duration: 0.2s;
  -ms-animation-duration: 0.2s;
  animation-duration: 0.2s;
  -webkit-animation-iteration-count: infinite;
  -moz-animation-iteration-count: infinite;
  -o-animation-iteration-count: infinite;
  -ms-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
  -webkit-animation-direction: alternate;
  -moz-animation-direction: alternate;
  -o-animation-direction: alternate;
  -ms-animation-direction: alternate;
  animation-direction: alternate;
}
@-moz-keyframes ag-shake-left-to-right {
  from {
    padding-left: 6px;
    padding-right: 2px;
  }
  to {
    padding-left: 2px;
    padding-right: 6px;
  }
}
@-webkit-keyframes ag-shake-left-to-right {
  from {
    padding-left: 6px;
    padding-right: 2px;
  }
  to {
    padding-left: 2px;
    padding-right: 6px;
  }
}
@-o-keyframes ag-shake-left-to-right {
  from {
    padding-left: 6px;
    padding-right: 2px;
  }
  to {
    padding-left: 2px;
    padding-right: 6px;
  }
}
@keyframes ag-shake-left-to-right {
  from {
    padding-left: 6px;
    padding-right: 2px;
  }
  to {
    padding-left: 2px;
    padding-right: 6px;
  }
}