Month Sorting

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/controls/wijmo.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.olap.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.211/controls/wijmo.xlsx.min.js"></script>
<!-- mark this as an Angular application and give it a controller -->
<div ng-app="app" ng-controller="appCtrl" class="container">
  <h1>OLAP Pivot Grid</h1>
  <wj-pivot-grid
    items-source="ngFmt"
    control="pivotGrid"
    initialized="init(s,e)">
  </wj-pivot-grid>
</div>

JavaScript

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

// controller
app.controller('appCtrl', function($scope) {
	var ascending = true;
  var data = [],
    countries = 'Spain,Russia'.split(','),
    colors = 'Red,Green,Blue'.split(','),
    products = 'Banana,Apple,Melon'.split(','),
    months='Jan,Feb,Mar,April,May'.split(',');
  for (var i = 0; i <= 25; i++) {
    data.push({
      id: i,
      country: countries[i % countries.length],
      color: colors[i % colors.length],
      product: products[i % products.length],
      sales: 10 * i*i + 100,
      expenses: 5 * i + 30,
      months:months[i % months.length]
    });
  }
  //$scope.cv = new wijmo.collections.CollectionView(data);
  
  var ng = new wijmo.olap.PivotEngine({
  	autoGenerateFields: false,
    itemsSource: data,
    showColumnTotals: wijmo.olap.ShowTotals.GrandTotals,
    showRowTotals: wijmo.olap.ShowTotals.Subtotals,
    fields: 'country,product,color,sales,expenses,months'.split(','),
    rowFields: 'Months,Country,Product'.split(','),
    valueFields: 'Sales,Expenses'.split(','),
   // columnFields: ['Color']
    
  });
  
  ng.fields.getField('Sales').aggregate = 'Sum';
  ng.fields.getField('Expenses').aggregate = 'Sum';
  ng.fields.forEach(function (field) {
            field.sortComparer = function (val1, val2) {
                var index1 = findIndex(data, field.binding, val1),
                    index2 = findIndex(data, field.binding, val2);
                return index1 - index2;
            };
        });
        function findIndex(arr, fld, val) {
            for (var i = 0; i < arr.length; i++) {
                if (arr[i][fld] == val) return i;
            }
            return -1;
        }
 	$scope.ngFmt = ng;
   $scope.export = function(){
  	var flex = true,
    		workbook,
        workSheet;
    if (flex){
    	workbook = wijmo.grid.xlsx.FlexGridXlsxConverter.save(ng);
      workSheet = workbook.sheets[0];
      addColumnHeaders(workSheet);
   ...