Wijmo 5 - FlexGrid Cell Templates

by Joel Parks

HTML

<script src="http://cdn.wijmo.com/5.20151.51/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.20151.51/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20151.51/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20151.51/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>FlexGrid Cell Templates</h1>

    <wj-flex-grid
      items-source="data" selection-mode="Row"
      selection-changed='selectionChanged(s,e)'
			initialized="initGrid(s,e)">
      <wj-flex-grid-column
          header="Country"
          binding="country"></wj-flex-grid-column>
      <wj-flex-grid-column 
          header="Custom" 
          width="120">
          <img width="40px" src="http://flagpedia.net/data/flags/mini/{{$item.abb}}.png" />
          <button ng-click="clickItem('{{$item.country}}')">
                Click me</button>
        </wj-flex-grid-column>
        <wj-flex-grid-column 
            header="Sales" 
            binding="sales"></wj-flex-grid-column>
        <wj-flex-grid-column 
            header="Expenses" 
            binding="expenses"></wj-flex-grid-column>
        <wj-flex-grid-column 
            header="Downloads" 
            binding="downloads"></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(','),
        abb = 'us,de,gb,jp,it,gr'.split(','),                                     
        data = [];
    for (var i = 0; i < countries.length; i++) {
        data.push({
            country: countries[i],
            abb: abb[i],
            downloads: Math.round(Math.random() * 20000),
            sales: Math.random() * 10000,
            expenses: Math.random() * 5000
        });
    }

    // expose data as a CollectionView to get events
    $scope.data = new wijmo.collections.CollectionView(data);
    
    // log selection changes
    $scope.selectionChanged = function(s, e) {
        console.log('changed ' + new Date().getTime());
    };
		
		$scope.initGrid = function(s,e) {
				//s.startEditing(true, 0, 0, true);
		}
    
    // handle button clicks
    $scope.clickItem = function(country) {
        alert('thanks for selecting ' + country);
    };
});