FlexSheet - Multiple column headers

by Troy Taylor

HTML

<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.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.sheet.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.xlsx.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.xlsx.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.xlsx.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<div ng-app="app" ng-controller="appCtrl" class="container">
  <h1>FlexSheet</h1>
  <h4>with mulitple column header rows</h4>
  <div class="form-inline">
 <input type="file"
    id="importFile"
    class="form-control"
    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
    <button class="btn btn-default" ng-click="loadFile()">Load</button>
    <button class="btn btn-default" id="saveBtn" ng-click="save()">Save</button>
 </div>
 <br>
  <wj-flex-sheet id="flex" control="ctx.flex" initialized="initialized(s)" allow-merging="AllHeaders" class="flexSheet">
    <wj-sheet items-source="ctx.data"></wj-sheet>
    <wj-sheet items-source="ctx.data2"></wj-sheet>
  </wj-flex-sheet>
</div>

CSS

.flexSheet {
	height: 600px;
	border: 2px solid #e0e0e0;
	margin: 6px;
}

JavaScript

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

// controller
app.controller('appCtrl', function($scope) {
  $scope.ctx = {
    flex: null,
    data: getData(),
    data2: getData2()
  };
  
  $scope.initialized = function(flexSheet) {
    
    flexSheet.sheets.selectedIndex = 0;
		
  };
  
  $scope.loadFile = function() {
  	console.log("load");
    var flexSheet = $scope.ctx.flex;
    var fileInput = document.getElementById('importFile');
    if (flexSheet && fileInput.files[0]) {
    	flexSheet.loadAsync(fileInput.files[0]);
    }
  }
  
  $scope.save = function() {
  	console.log("save");
    var flexSheet = $scope.ctx.flex;
    if (flexSheet) {
    	flexSheet.saveAsync("FlexSheet.xlsx", function (base64) {

     // user can access the base64 string in this callback.
     document.getElementById('importFile').href = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;' + 'base64,' + base64;
     console.log(base64);
    }, function (reason) {

       // User can catch the failure reason in this callback.
       console.log('The reason of save failure is ' + reason);
  });
    }
  }
  
  function getData() {
    var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
        data = [];
    for (var i = 0; i < 10 * countries.length; i++) {
      data.push({
        id: i,
        country: countries[i % countries.length],
        downloads: Math.round(Math.random() * 20000),
        sales: Math.random() * 10000,
        expenses: Math.random() * 5000
      });
    }
    //return data;
    
    var cv = wijmo.collections.CollectionView(data, {
    	groupDescriptions: ['Country']
    });
    return cv;
  }
  
  function getData2(){
  	var products = ['Widget', 'Gadget', 'Doohickey'],
    		colors = ['Black', 'White', 'Red', 'Green', 'Blue'],
    		data = [];
    for (var i = 0; i < 10 * products.length; i++) {
      data.push({
        id: i,
        product: products[i % products.length],
       ...