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,
customizeCell: customizeCellFunction,
report: {
dataSource: {
filename: "data/data.csv",
},
slice: {
rows: [
{
uniqueName: "Category",
},
],
columns: [
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "Quantity",
aggregation: "sum",
},
{
uniqueName: "Discount %",
formula: 'sum("Discount")/sum("Price")',
caption: "Discount %",
},
],
},
formats: [
{
name: "",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: 2,
nullValue: "-",
},
],
},
})
function customizeCellFunction(cell, data) {
if (data.rowIndex % 2 == 0 && data.type == "value") {
cell.text = cell.text + "%"
}
}
function excel() {
pivot.exportTo("excel", {
excelSheetName: "Pivot Table",
})
}