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>
<select id='fields'>
</select>
<input id='captionInput' type='text' placeholder='enter new caption'>
<button onclick="customCaption()">Apply custom caption</button>
<div id="pivotContainer"></div>
CSS
select,
input {
border: 2px solid #333;
background: #fff;
color: #333;
margin: 5px 0;
display: inline-block;
transition: all .3s;
font-weight: normal;
padding: 10px 10px;
font-size: 14px;
}
select,
button {
text-transform: uppercase;
cursor: pointer;
}
option {
cursor: pointer;
}
JavaScript
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
height: 700,
report: {
dataSource: {
type: "microsoft analysis services",
proxyUrl: "https://olap.flexmonster.com:8085/FlexmonsterProxy/",
catalog: "Adventure Works DW Standard Edition",
cube: "Adventure Works",
binary: true
},
slice: {
rows: [
{ uniqueName: "[Geography].[Geography]" }
],
columns: [
{
uniqueName: "[Product].[Category]"
},
{
uniqueName: "[Measures]"
}
],
measures: [
{
uniqueName: "[Measures].[Reseller Order Count]"
},
{
uniqueName: "[Measures].[Discount Amount]"
}
],
drills: {
rows: [
{
tuple: [
"[Geography].[Geography].[Country].&[Australia]"
]
},
{
tuple: [
"[Geography].[Geography].[Country].&[Canada]"
]
}
]
}
}
}
});
pivot.on("reportcomplete", () => {
//pivot.off("reportcomplete");
const selectElement = document.getElementById('fields');
const fields = pivot.getAllHierarchies();
selectElement.innerHTML = '';
fields.forEach(field => {
const option = document.createElement('option');
option.value = field.uniqueName;
option.textContent = field.caption;
selectElement.appendChild(option);
});
})
function customCaption() {
const input = document.getElementById('captionInput');
const select = document.getElementById('fields');
let newCaption = input.value;
let field = select.value;
if (newCaption.length == 0) return;
let newReport = pivot.getReport();
if (!newReport.dataSource.mapping) {
newReport.dataSource.mapping = {};
}
newReport.dataSource.mapping[field] = {
type: "string",
caption: newCaption
};
...