JSFiddle - React, Tailwind, and code Playground

Export and print

by Flexmonster Pivot Table

HTML

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

<button onclick="excel()">Export to excel</button>

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

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv",
    },
    slice: {
      rows: [
        {
          uniqueName: "Category",
        },
      ],
      columns: [
        {
          uniqueName: "[Measures]",
        },
      ],
      measures: [
        {
          uniqueName: "Price",
          aggregation: "sum",
          format: "currency"
        },
        {
          uniqueName: "Discount %",
          formula: 'sum("Discount")/sum("Price")',
          caption: "Discount %",
          format: "discount",
        },
      ],
    },
    formats: [ {
        name: "",
        thousandsSeparator: ",",
        decimalSeparator: ".",
        decimalPlaces: 2,
        nullValue: "-"
      },
      {
        name: "currency",
        currencySymbol: "$"
      },
      {
        name: "discount",
        decimalPlaces: 2,
        isPercent: true,
      },
    ],
  },
})

function excel() {
  pivot.exportTo("excel", {
    excelSheetName: "Pivot Table",
  })
}