Hi
I want to display the subtotals in my flex pivot, but I don't want to export them.
Is it possible ?
Thanks
Franck
Hello, Franck,
Thank you for reaching out to us.
We have prepared a JSFiddle demonstrating the requested functionality: https://jsfiddle.net/flexmonster/z8e0sLy7/.
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
pivot.off("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 => tab.id == "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", () => {
pivot.off("aftergriddraw");
hanlder();
});
pivot.customizeCell(hideSubotals);
}
});
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: https://www.flexmonster.com/doc/customizing-toolbar/.
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: https://jsfiddle.net/flexmonster/3t01f7zc/.
Please let us know if it works for you.
Our team is looking forward to hearing your feedback.
Regards,
Illia
Hello, Franck,
We are reaching out to ask if the suggested solution works for you.
Regards,
Illia
Hi
Yes it works for me
Thanks
Franck