Managing grand totals with the grid.showGrandTotals option
Options
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<button onclick="turnOnTotals()">Turn on totals</button>
<button onclick="turnOffTotals()">Turn off totals</button>
<button onclick="totalsInRows()">Show totals for rows</button>
<button onclick="totalsInColumns()">Show totals for columns</button>
<div id="pivot-container"></div>
CSS
@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);
#fm-pivot-view .fm-grid-layout .fm-grand-total {
background-color: #e9f4ed !important;
}
JavaScript
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
report: {
dataSource: {
filename: "data/data.csv",
},
slice: {
rows: [
{
uniqueName: "Color",
},
],
columns: [
{
filter: {
members: [
"country.[canada]",
"country.[germany]",
"country.[united kingdom]",
],
},
uniqueName: "Country",
},
],
measures: [
{
uniqueName: "Price",
},
],
},
},
});
function turnOffTotals() {
let options = pivot.getOptions();
options.grid.showGrandTotals = "off";
pivot.setOptions(options);
pivot.refresh();
}
function turnOnTotals() {
let options = pivot.getOptions();
options.grid.showGrandTotals = "on";
pivot.setOptions(options);
pivot.refresh();
}
function totalsInRows() {
let options = pivot.getOptions();
options.grid.showGrandTotals = "rows";
pivot.setOptions(options);
pivot.refresh();
}
function totalsInColumns() {
let options = pivot.getOptions();
options.grid.showGrandTotals = "columns";
pivot.setOptions(options);
pivot.refresh();
}