Wijmo 5 - Dynamic ItemFormatter

HTML

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.chart.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<!-- mark this as an Angular application and give it a controller -->
<div ng-app="app" ng-controller="appCtrl">

  <h1>
    Custom Display Cell Template
  </h1>
  <p>
    This fiddle shows a custom display cell template.
  </p>
  <wj-flex-grid items-source="data">
    <wj-flex-grid-column header="Custom Cell" binding="value">
      <wj-flex-grid-cell-template cell-type="Cell">
        <custom-display-cell></custom-display-cell>
      </wj-flex-grid-cell-template>
    </wj-flex-grid-column>
  </wj-flex-grid>
</div>

JavaScript

// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);

// controller
app.controller('appCtrl', function($scope) {
  // create some random data
  var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
    data = [];
  for (var i = 0; i < countries.length; i++) {
    data.push({
      value: countries[i]
    });
  }

  // expose data as a CollectionView to get events
  $scope.data = new wijmo.collections.CollectionView(data);
});

var template = '<div><span title="{{titleValue}}">{{$item.value}}</span><button style="float: right" ng-mousedown="openAlert($row.index, $col.index)">?</button></div>';

// directive
app.directive('customDisplayCell', function() {
  return {
    restrict: 'E',
    replace: true,
    template: template,
    controller: function($scope) {
      $scope.titleValue = "The country is " + $scope.$item.value;
      $scope.openAlert = function(rowIndex, colIndex) {
        alert($scope.$item.value + ' on ROW: ' + rowIndex + ' COL: ' + colIndex);
      };
    }
  };
});