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="printChecked()">Get checked</button>
<div id="pivot-container"></div>
CSS
#fm-cols-sheet>div>div.fm-ui-element.fm-scroll-content>div:nth-child(2)>div:nth-child(1)>i.fm-icon.fm-filter-icon,
#fm-cols-sheet>div>div.fm-ui-element.fm-scroll-content>div:nth-child(2)>div:nth-child(1)>i.fm-icon.fm-sort-icon.fm-v-sort-icon {
display: none !important;
}
#fm-cols-sheet>div>div.fm-ui-element.fm-scroll-content>div:nth-child(2)>div:nth-child(1) {
pointer-events: none;
}
JavaScript
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
data: getData()
},
slice: {
rows: [{
uniqueName: "ID"
},
{
uniqueName: "Serial number"
},
{
uniqueName: "Hostname"
}
],
measures: [{
uniqueName: "Serial number"
}]
},
options: {
showGrandTotals: "off",
grid: {
type: "flat"
}
},
tableSizes: {
columns: [{
idx: 0,
width: 1
}]
}
}
});
let prev;
pivot.on('cellclick', (data) => {
if (data.type == "value" && data.measure && data.measure.uniqueName == 'ID')
alert(data.value);
});
pivot.on('reportcomplete', () => {
prev = pivot.getOptions();
if (pivot.getOptions().viewType == 'grid' && pivot.getOptions().grid.type == 'flat')
drawCheckboxes();
});
pivot.on('reportchange', addCheckboxes);
function addCheckboxes() {
pivot.off('reportchange', addCheckboxes);
let options = pivot.getOptions();
if (options.viewType != prev.viewType || options.grid.type != prev.grid.type || options.chart.type != prev.chart.type)
if (options.viewType == 'grid' && options.grid.type == 'flat') {
let report = pivot.getReport();
report.slice.rows.unshift({
uniqueName: 'ID'
});
report.slice.flatOrder = ['ID'];
report.tableSizes = {
columns: [{
idx: 0,
width: 1
}]
}
pivot.setReport(report);
drawCheckboxes();
} else {
let report = pivot.getReport();
report.slice.rows = report.slice.rows.filter(x => {
return x.uniqueName != 'ID';
});
delete report.tableSizes;
pivot.setReport(report);
}
pivot.on('reportchange', addCheckboxes);
prev = pivot.getOptions();
}
function drawCheckboxes() {
pivot.customizeCell((cell, data) => {
if...