Wijmo 5 - [Flex Grid]

Merging columns and rows and set background color for each column header

by Manish Gupta

HTML

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://cdn.wijmo.com/5.20143.24/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.20143.24/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20143.24/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20143.24/controls/wijmo.chart.min.js"></script>
<script src="http://cdn.wijmo.com/5.20143.24/interop/angular/wijmo.angular.min.js"></script>
  <div ng-app="app" ng-controller="appCtrl" style="margin:10px;">
        <wj-flex-grid control="flex" items-source="data" item-formatter="itemFormatter">
        </wj-flex-grid>
    </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);
            $scope.itemFormatter = function (panel, r, c, cell) {
               // set background color fro column header
                if (panel.cellType == wijmo.grid.CellType.ColumnHeader) {
                    console.log(panel.columns[c]);
                    if(cell.innerHTML=='Merged rows')
                        cell.style.backgroundColor = '#9E9D24';                    
                    if (cell.innerHTML == 'Merged Columns')
                        cell.style.backgroundColor = '#03A9F4';
                    if (cell.innerHTML == 'GG')
                        cell.style.backgroundColor = '#00796B';
                    if (cell.innerHTML == 'downloads'||cell.innerHTML=='sales')
                        cell.style.backgroundColor = '#388E3C';
                    
                    if(cell.innerHTML=='expenses')
                        cell.style.backgroundColor = '#607D8B';
                }
            }
            $scope.$watch('flex', function () {
                var flex = $scope.flex;
                if (flex) {

                    // add some header rows
                    flex.columnHeaders.rows.push(new wijmo.grid.Row());
                   
                   ...