Highlight a certain member on the grid

Customizing the grid

HTML

<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div>
  <h2>How to highlight a certain member on the grid</h2>
  <p>
  This example demonstrates how to highlight certain members on the grid regardless of their position.
  </p>
  <p>
  To highlight members, we use the <a href="https://www.flexmonster.com/api/customizecell/" target="_blank">customizeCell()</a> method. For each cell, we check if the cell contains the needed member. If it does, we add the <code>highlight</code> CSS class to that cell (lines 38-56 in the JavaScript box).
  </p>
  <p>
  In this example, we've highlighted the <code>Canada</code>, <code>Germany</code>, and <code>Warehouse</code> members.
  </p>
  <p>
  <a href="https://www.flexmonster.com/doc/customizing-grid/" target="_blank">Visit our docs to learn more about customizing the grid</a>.
  </p>
</div>

<button onclick="clearCustomizing()">Clear Customizing</button>
<button onclick="startCustomizing()">Start Customizing</button>

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

CSS

.highlight {
  background-color: #FFB74D !important;
}

/********************* Styles for the description *********************/

h2 {
  text-align: center;
}

p {
  font-size: 15px;
  line-height: 1.5;
  padding-right: 10px;
  padding-left: 10px;
}

a {
  color: #00a45a;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
    font-size: 105%;
    color: #DF3800;
    background-color: #f5f5f5;
    padding: 1px 4px;
    font-family: monospace !important;
    border-radius: 4px;
}

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  customizeCell: customizeCellFunction,
  report: {
    dataSource: {
      filename: "data/data.json"
    },
    slice: {
      rows: [
        {
          uniqueName: "Country"
        }, 
        {
          uniqueName: "Color"
        }
      ],
      columns: [
        {
          uniqueName: "[Measures]"
        }, 
        {
          uniqueName: "Business Type"
        }
      ],
      measures: [{
        uniqueName: "Price"
      }]
    }
  }
});

const highlightedMembers = {
  "Country": ["Canada", "Germany"],
  "Business Type": ["Warehouse"]
}

function customizeCellFunction(cell, data) {
  if (data.rows) {
    data.rows.forEach(row => {
      if (highlightedMembers[row.hierarchyName] &&
        highlightedMembers[row.hierarchyName].includes(row.caption)) {
        cell.addClass("highlight");
      }
    });
  }
  
  if (data.columns) {
    data.columns.forEach(column => {
      if (highlightedMembers[column.hierarchyName] &&
        highlightedMembers[column.hierarchyName].includes(column.caption)) {
        cell.addClass("highlight");
      }
    });
  }
}

function clearCustomizing() {
  pivot.customizeCell(null);
}

function startCustomizing() {
  pivot.customizeCell(customizeCellFunction);
}