Repeat labels in the classic (tabular) view

Customizing the grid

by Flexmonster Pivot Table

HTML

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

<div>
  <h2>How to repeat labels in the classic (tabular) view</h2>
  <p>
    To repeat labels in the classic view, we use the
    <a href="https://www.flexmonster.com/api/grid-options-object/#repeatalllabels" target="_blank"
      >grid.repeatAllLabels</a
    >
    option (line 28 in the JavaScript box).
  </p>
  <p>
    <a href="https://www.flexmonster.com/doc/options/" target="_blank"
    >Learn more about Flexmonster's options in our documentation</a>.
  </p>
  <p>
    Please note that the <code>grid.repeatAllLabels</code> option
    is available starting from version 2.9.119. If your version of Flexmonster
    is 2.9.118 or older, see
    <a href="https://jsfiddle.net/flexmonster/zkm26d6h/" target="_blank"
      >this example</a>.
  </p>
</div>

<div class="switch-container compact">
  <span class="text">Repeat row labels</span>
  <label class="switch">
    <input type="checkbox" checked id="repeatLabelsToggle" onclick="toggleRepeatLabels()" />
    <span class="slider round"></span>
  </label>
</div>

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

CSS

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

JavaScript

const pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.json"
    },
    slice: {
      rows: [
      	{ uniqueName: "Country" }, 
      	{ uniqueName: "Color" }, 
      	{ uniqueName: "Category" }
    	],
      columns: [
      	{ uniqueName: "[Measures]" }
      ],
      measures: [
      	{ uniqueName: "Price" }
      ],
      expands: {
        expandAll: true
      }
    },
    options: {
      grid: {
        type: "classic",
        repeatAllLabels: true,
        showTotals: "off"
      }
    }
  }
});

function toggleRepeatLabels() {
  const options = pivot.getOptions();
  const repeatLabelsToggle = document.getElementById("repeatLabelsToggle");
      
  options.grid.repeatAllLabels = repeatLabelsToggle ? repeatLabelsToggle.checked : !options.repeatAllLabels;
  
  pivot.setOptions(options);
  pivot.refresh();
}