☝️Small business or a startup? See if you qualify for our special offer.
+
List of all demos

JavaScript Pivot Table: classic (tabular) view

The classic (tabular) form is a pivot table view that gives an Excel-like layout of hierarchies. With the classic pivot table, you can show hierarchy sublevels next to one another, in separate rows or columns.


    const pivot = new Flexmonster({
      container: "#pivot-container",
      componentFolder: "https://cdn.flexmonster.com/",
      height: 450,
      report: {
        dataSource: {
          type: "csv",
          filename: "https://cdn.flexmonster.com/data/data.csv",
        },
        options: {
          grid: {
            type: "classic",
          },
        },
        slice: {
          rows: [
            {
              uniqueName: "Country",
            },
            {
              uniqueName: "Business Type",
            },
          ],
          columns: [
            {
              uniqueName: "Color",
            },
            {
              uniqueName: "[Measures]",
            },
          ],
          measures: [
            {
              uniqueName: "Price",
              format: "currency"
            },
          ],
          expandAll: true,
        },
       formats: [
          {
            name: "",
            thousandsSeparator: ",",
            decimalSeparator: ".",
            decimalPlaces: 2,
          },
          {
            name: "currency",
            currencySymbol: "$",
          },
        ],
      },
    });
    
    function changeLayout(layoutType) {
      pivot.setOptions({
        grid: {
          type: layoutType,
        },
      });
      pivot.refresh();
    }
    
    
    function customizeCellFunction(cell, data) {
      if (
        data &&
        data.type == "header" &&
        data.member &&
        data.member.caption != "All" &&
        data.label == ""
      ) {
        cell.text = "    " + data.member.caption
      }
    }
    
    function setRepeatLabels(enabled) {
      pivot.customizeCell(enabled ? customizeCellFunction : null);
    }
    
    <button onclick="changeLayout('compact')">Use compact form</button>
    <button onclick="changeLayout('classic')">Use classic form</button>
    <button onclick="setRepeatLabels(true)">Repeat labels on</button>
    <button onclick="setRepeatLabels(false)">Repeat labels off</button>
    
    <div id="pivot-container"></div>
    

    By default, grand totals are displayed at the end of each row, and subtotals are placed in a separate row at the bottom.

    All the pivot table functionality works the same way: you can drag and drop, expand, collapse, drill down and up the hierarchies, sort and drill through values, and more. Just do it the way you're used to in Excel.

    If multilevel hierarchies from your report contain a lot of sublevels, we recommend switching to the compact form, which shows them more neatly.