Wijmo FlexSheet
add a column header row
by Joel Parks
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.wijmo.com/5.20173.403/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20173.403/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.20173.403/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.20173.403/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20173.403/controls/wijmo.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.20173.403/controls/wijmo.grid.sheet.min.js"></script>
<script src="http://cdn.wijmo.com/5.20173.403/interop/angular/wijmo.angular.min.js"></script>
<div ng-app="app" ng-controller="appCtrl">
<div class="container">
<h1>FlexSheet</h1>
<p>
</p>
<wj-flex-sheet initialized="initialized(s)" item-formatter="itemFormatter">
<wj-sheet name="Country" items-source="ctx.data"></wj-sheet>
<wj-sheet name="Empty Sheet"></wj-sheet>
</wj-flex-sheet>
</div>
</div>
CSS
.wj-flexsheet {
height: 400px;
background-color: white;
box-shadow: 4px 4px 10px 0px rgba(50, 50, 50, 0.75);
margin-bottom: 12px;
}
JavaScript
// declare app module
var app = angular.module('app', ['wj']);
// app controller provides data
app.controller('appCtrl', function ($scope) {
var countries = [ 'US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece' ];
$scope.ctx = {
data: getData(50),
flexSheet: null,
products: [ '0', '1', '2' ],
countries: [ 'US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece' ],
//active: i % 2 != 0
}
// });
// initialize the flexSheet control when document ready.
$scope.initialized = function (s) {
console.log(s);
s.deferUpdate(function () {
var column;
for (var i = 0; i < s.sheets.length; i++) {
s.sheets.selectedIndex = i;
if (s.sheets[i].name === 'Country') {
initDataMapForBindingSheet(s);
}
}
s.selectedSheetIndex = 0;
});
};
$scope.itemFormatter = function(panel, r, c, cell){
panel.grid.columns[5].dataType = 3;
if(panel.cellType == 1) {
if(c == 5){
if(cell.innerHTML == 0) {
panel.grid.setCellData(r, c, false);
}
}
}
}
// initialize the dataMap for the bound sheet.
function initDataMapForBindingSheet(flexSheet) {
var column;
if (flexSheet) {
column = flexSheet.columns.getColumn('countryId');
if (column && !column.dataMap) {
column.dataMap = buildDataMap(getCountries());
}
column = flexSheet.columns.getColumn('productId');
if (column && !column.dataMap) {
column.dataMap = buildDataMap(getProducts());
}
}
};
// build a data map from a string array using the indices as keys
function buildDataMap(items) {
var map = [];
for (var i = 0; i < items.length; i++) {
map.push({ key: i, value: items[i] });
}
...