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: getData(),
},
slice: {
rows: [
{
uniqueName: "company_name",
caption: "Company",
},
],
columns: [
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "only_unemployed",
formula: "if(max('cl_pea_id_v1')==2, sum('OBS_VALUE'),0)",
individual: true,
active: false,
},
{
uniqueName: "only_active",
formula: "if(max('cl_pea_id_v1')<3, sum('OBS_VALUE'),0)",
individual: true,
active: false,
},
{
uniqueName: "Unemployment rate",
formula: "sum('only_unemployed')/sum('only_active')",
format: "percents",
},
],
},
formats: [
{
name: "percents",
isPercent: true,
},
],
},
})
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",
},
]
}