Highlighting cells on a certain level using customizeCell (for versions before 2.8.16)

Customizing the grid

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/2.8.15/flexmonster.js"></script>

<p>
  Note that <code>customizeCell()</code> isn't needed to highlight cells on a
  certain level in Flexmonster versions 2.8.16 and later. Check out
  <a href="https://jsfiddle.net/flexmonster/qf4c5zL8/">this example</a> if your
  version of Flexmonster is higher than 2.8.15.
</p>

<div id="pivot-container"></div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

/* Grid styles */

#fm-pivot-view #fm-grid-view div.fm-level-0.fm-cell,
#fm-pivot-view #fm-grid-view div.fm-level-0.fm-cell.fm-header,
#fm-pivot-view #fm-grid-view div.fm-level-0.fm-cell.fm-total {
  background-color: #674EA7;
  border-bottom: 1px solid #674EA7;
  border-right: 1px solid #674EA7;
  color: white;
}

#fm-pivot-view #fm-grid-view div.fm-level-1.fm-cell,
#fm-pivot-view #fm-grid-view div.fm-level-1.fm-cell.fm-header,
#fm-pivot-view #fm-grid-view div.fm-level-1.fm-cell.fm-total {
  background-color: #8E7CC3;
  border-bottom: 1px solid #8E7CC3;
  border-right: 1px solid #8E7CC3;
  color: white;
}

#fm-pivot-view #fm-grid-view div.fm-level-2.fm-cell,
#fm-pivot-view #fm-grid-view div.fm-level-2.fm-cell.fm-header,
#fm-pivot-view #fm-grid-view div.fm-level-2.fm-cell.fm-total {
  background-color: #D9D2E9;
  border-bottom: 1px solid #D9D2E9;
  border-right: 1px solid #D9D2E9;
}

#fm-pivot-view #fm-grid-view div.fm-level-0.fm-cell.fm-header:hover,
#fm-pivot-view #fm-grid-view div.fm-level-1.fm-cell.fm-header:hover,
#fm-pivot-view #fm-grid-view div.fm-level-2.fm-cell.fm-header:hover {
  color: #000;
  border: none;
}

#fm-pivot-view #fm-grid-view div.fm-level-0.fm-cell.fm-header i.fm-icon::before {
  color: #d3c8e5;
}

#fm-pivot-view #fm-grid-view div.fm-level-1.fm-cell.fm-header i.fm-icon::before {
  color: #d3c8e5;
}

#fm-pivot-view #fm-grid-view div.fm-level-2.fm-cell.fm-header i.fm-icon::before {
  color: #8E7CC3;
}

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/2.8.15/",
  licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
  customizeCell: customizeCellFunction,
  height: 600,
  report: {
    dataSource: {
      filename: "https://cdn.flexmonster.com/data/data.json"
    },
    slice: {
      rows: [{
        uniqueName: "Country"
      }, {
        uniqueName: "Business Type"
      }, {
        uniqueName: "Category"
      }, {
        uniqueName: "[Measures]"
      }],
      columns: [{
        uniqueName: "Color"
      }],
      measures: [{
        uniqueName: "Price"
      }],
      expands: {
        rows: [{
            tuple: [
              "country.[australia]"
            ]
          },
          {
            tuple: [
              "country.[australia]",
              "business type.[warehouse]"
            ]
          }
        ]
      }
    },
    options: {
      grid: {
        type: "classic"
      }
    }
  }
});

function customizeCellFunction(cell, data) {
  if (data.level != undefined) {
    cell.addClass("fm-level-" + data.level);
  }
}