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>
<div id="pivot-container"></div>
JavaScript
const pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
data: prepareData(),
},
slice: {
rows: [
{
uniqueName: "company_name",
caption: "Company",
},
],
columns: [
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "Unemployment rate",
formula: "(sum('OBS_VALUE')-sum('OBS_VALUE_EMPLOYED'))/sum('OBS_VALUE')",
format: "percents",
},
],
},
formats: [
{
name: "percents",
isPercent: true,
},
],
},
})
function prepareData() {
return getData()
.filter(d => d.cl_pea_id_v1 !== 3)
.map(d =>
d.cl_pea_id_v1 === 1
? { ...d, OBS_VALUE_EMPLOYED: d.OBS_VALUE }
: d
);
}
function getData() {
return [
{
OBS_VALUE: 10,
cl_pea_id_v1: 1, //employed
company_name: "Company A",
},
{
OBS_VALUE: 10,
cl_pea_id_v1: 2, //unemployed
company_name: "Company A",
},
{
OBS_VALUE: 10,
cl_pea_id_v1: 3, //inactive
company_name: "Company A",
},
{
OBS_VALUE: 15,
cl_pea_id_v1: 1,
company_name: "Company B",
},
{
OBS_VALUE: 5,
cl_pea_id_v1: 2,
company_name: "Company B",
},
{
OBS_VALUE: 5,
cl_pea_id_v1: 3,
company_name: "Company B",
},
]
}