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
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
beforetoolbarcreated: customizeToolbar,
report: {
dataSource: {
filename: "data/sales.csv"
},
"slice": {
"rows": [{
"uniqueName": "Region"
}],
"columns": [{
"uniqueName": "[Measures]"
},
{
"uniqueName": "Salesperson"
}
],
"measures": [{
"uniqueName": "Unit Price",
"aggregation": "sum"
}]
}
}
});
function customizeToolbar(toolbar) {
// get all tabs
var tabs = toolbar.getTabs();
toolbar.getTabs = function() {
// reposition the "Export" Tab:
const isExportTab = (tab) => tab.id == "fm-tab-export";
const isFormatTab = (tab) => tab.id == "fm-tab-format";
reposition(tabs, tabs.findIndex(isExportTab), tabs.findIndex(isFormatTab));
// add the "Export" Tab to the rightGroup:
tabs[tabs.findIndex(isExportTab)].rightGroup = true;
return tabs;
}
}
function reposition(arr, old_index, new_index){
while (old_index < 0) {
old_index += arr.length;
}
while (new_index < 0) {
new_index += arr.length;
}
if (new_index >= arr.length) {
let k = new_index - arr.length;
while ((k--) + 1) {
arr.push(undefined);
}
}
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
return arr;
}