Multiple column headers
by Mike Lu
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">
<div ng-app="app" ng-controller="appCtrl" class="container">
<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: 400px;
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.updatedView.addHandler(function(){
var colHeaders = flexSheet.hostElement.querySelector('div [wj-part="chcells"]');
if (colHeaders){
for (var i = 0; i < colHeaders.childElementCount; i++){
var row = colHeaders.childNodes[i];
for (var j = 0; j < row.childElementCount; j++){
var cell = row.childNodes[j];
var cellInfo = cell['wj-cell-index'];
if (cell && cell.childNodes.length > 1){
cell.childNodes[1].nodeValue = flexSheet.columns[cellInfo.col].header;
}
}
}
}
/*setTimeout(function(){
if(!flexSheet.rows[0].dataItem){
//flexSheet.rows.splice(0,1);
flexSheet.rows[0].visible=false;
}
});*/
if (flexSheet.rows[0] instanceof wijmo.grid.sheet.HeaderRow){
flexSheet.rows.removeAt(0);
}
});
};
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;
}
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],
color: colors[i % colors.length],
date: new Date(2016, i % 12, i % 28),
amount:...