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

React Pivot Table: classic (tabular) view

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


    import React from "react";
    import * as FlexmonsterReact from "react-flexmonster";
    
    class PivotTableDemo extends React.Component {
      constructor(props) {
        super(props);
        this.pivot = React.createRef();
        this.state = {
          customizeCellEnabled: false,
        };
      }
    
      changeLayout = (layoutType) => {
        this.pivot.current.flexmonster.setOptions({
          grid: {
            type: layoutType,
          },
        });
        this.pivot.current.flexmonster.refresh();
      };
    
      customizeCellFunction = (cell, data) => {
        if (
          data &&
          data.type === "header" &&
          data.member &&
          data.member.caption !== "All" &&
          data.label === ""
        ) {
          cell.text = "    " + data.member.caption;
        }
      };
    
      setRepeatLabels = (enabled) => {
        this.setState({ customizeCellEnabled: enabled }, () => {
          this.pivot.current.flexmonster.customizeCell(
            enabled ? this.customizeCellFunction : null
          );
        });
      };
    
      render() {
        return (
          <>
            <button onClick={() => this.changeLayout("compact")}>Use compact form</button>
            <button onClick={() => this.changeLayout("classic")}>Use classic form</button>
            <button onClick={() => this.setRepeatLabels(true)}>Repeat labels on</button>
            <button onClick={() => this.setRepeatLabels(false)}>Repeat labels off</button>
    
            <FlexmonsterReact.Pivot
              ref={this.pivot}
              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: "$",
                  },
                ],
              }}
            />
          </>
        );
      }
    }
    
    export default PivotTableDemo;
    

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

    All the React pivot table functionality works similarly to what you're used to in Excel. You can drag and drop, expand, collapse, drill down and up the hierarchies, sort and drill through values, and more.

    In case multilevel hierarchies from your report include a lot of sublevels, it is better to switch to the compact form, which shows them more neatly and saves space on the page.