FlexGrid - formatItem

use formatItem to hightlight ColumnHeader

by Troy Taylor

HTML

<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
<div ng-app="app" ng-controller="appCtrl">

    <h2>formatItem event</h2>
    <wj-flex-grid control="flex" items-source="data" format-item="formatItem(s,e)">
        <wj-flex-grid-column header="Country" binding="country"></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>
    <button ng-click="invokeEvent()">
    invoke <strong>formatItem</strong> event
    </button>
</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({
            country: countries[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);
    
    // formatItem event handler
    $scope.formatItem = function(s,e) {
        var panel = e.panel,
          c = e.col;
       
        if(panel.cellType == wijmo.grid.CellType.ColumnHeader){
        	var column = panel.columns[c];
          if( column.header == 'Country'){
            e.cell.style.backgroundColor = "yellow";
          }
        }
    }
    
    $scope.invokeEvent = function(){
    	$scope.flex.onFormatItem();
    }
});