JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<button onclick='olapFormattingHandler()'>
Enable OLAP formatting
</button>
<div id="pivot-container"></div>
CSS
h2 {
text-align: center;
}
p {
font-size: 15px;
line-height: 1.5;
padding-right: 10px;
padding-left: 10px;
}
a {
color: #00a45a;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
code {
font-size: 105%;
color: #DF3800;
background-color: #f5f5f5;
padding: 1px 4px;
font-family: monospace !important;
border-radius: 4px;
}
JavaScript
const pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
height: 400,
toolbar: true,
beforetoolbarcreated: customizeToolbar,
report: {
dataSource: {
type: "microsoft analysis services",
proxyUrl: "https://olap.flexmonster.com/olap/msmdpump.dll",
cube: "Adventure Works",
catalog: "Adventure Works DW Standard Edition"
},
slice: {
rows: [{
uniqueName: "[Product].[Category]"
},
{
uniqueName: "[Reseller].[Business Type]"
}
],
columns: [{
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "[Measures].[Reseller Order Count]"
}]
},
options: {
useOlapFormatting: false
}
}
});
function customizeToolbar(toolbar) {
let tabs = toolbar.getTabs();
toolbar.getTabs = function() {
tabs.unshift({
id: "fm-tab-olap",
title: "OLAPformat",
handler: olapFormattingHandler,
icon: "<img src='https://bensullins.com/wp-content/uploads/2008/09/3D_Mesh_Cube.png'/>"
});
tabs = tabs.filter(tab => tab.id == "fm-tab-olap" || tab.id == "fm-tab-fullscreen");
return tabs;
}
}
const olapFormattingHandler = () => {
alert("Switching to OLAP number formatting");
pivot.setOptions({
useOlapFormatting: true
});
pivot.refresh();
}