Get Free Trial

Export without subtotals

Jaffrezic asked on April 15, 2021

I want to display the subtotals in my flex pivot, but I don’t want to export them.

Is it possible ?

3 answers

Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 15, 2021

Hello, Franck,
Thank you for reaching out to us.
We have prepared a JSFiddle demonstrating the requested functionality:
You can find the detailed explanation of this approach below:
First, we create the hideSubtotal function. It will serve as a callback handler for the customize cell API call. This function hides all the subtotals on the grid by replacing cells’ text with an empty string:

function hideSubotals(cell, data) {
  if (data.isTotal && !data.isGrandTotal)
    cell.text = "";

Next, we subscribe to the exportcomplete and printcomplete events and pass an empty customizeCell function as a handler. This part serves to restore subtotals after the export/printing is complete:

pivot.on("exportcomplete", pivot.customizeCell);
pivot.on("printcomplete", pivot.customizeCell);

Next, we create an actual export function that would invoke the hideSubtotals method, wait until the grid is redrawn (aftergriddraw event), and export/print the content (exportTo or print method):

  pivot.on("aftergriddraw", () => { //subscribe to the "aftergriddraw" event"aftergriddraw"); //unsubscribe from the "aftergriddraw" event to avoid looping
    flexmonster.exportTo(args); or flexmonster.print(args); //perform export
  pivot.customizeCell(hideSubotals); //hide subtotals and trigger the "aftergriddraw" event

In the JSFiddle, we have customized the Toolbar so that all the export buttons use the mentioned handler instead:

pivot.on("beforetoolbarcreated", (toolbar) => {
  let tabs = toolbar.getTabs(); //get all tabs
  toolbar.getTabs = () => {
    let exports = tabs.find(tab => == "fm-tab-export").menu; //get all buttons of the "Export" tab
    if (!exports) return;

    exports.forEach(tab => {
      let hanlder = //declare the handler
        tab.args ? () => { //check if the "args" property exists
          pivot.exportTo(tab.args) //if the "args" property exists, initialize the handler with an "exportTo" function
        } : () => {
          pivot.print() //if the "args" property does not exist, initialize the handler with an "print" function
      tab.handler = () => { //assign new tab's handler
        pivot.on("aftergriddraw", () => {

    return tabs; //return updated tabs

You can either use this approach or create custom controls for this type of export. For more information about the Toolbar customization:
If subtotals of collapsed members need to be preserved, we suggest replacing the customizeCell function with a setOptions API call in order to hide subtotals:
Please let us know if it works for you.
Our team is looking forward to hearing your feedback.

Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 21, 2021

Hello, Franck,
We are reaching out to ask if the suggested solution works for you.

Jaffrezic April 22, 2021

Yes it works for me

Please login or Register to Submit Answer