How to disable Aggregations on flat form alone

Closed
raviteja asked on October 20, 2022

HI Team,
I would like to disable select aggregation button for measures on flat form and should able to select in other formats like classic or compact.
I tried to set options as   showAggregations: false , I can able to disable for all the formats. But here I want to disable it only for flat form.
Can you suggest right approach for my requirement.
 
Thanks,
Ravi 

Attachments:
aggrgation_disbale.PNG

2 answers

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster October 20, 2022

Hello, Ravi!
 
Thank you for your question.
 
Kindly note that by default, it is possible to switch off the aggregations or other options only for all types of grid. 
To achieve the desired behavior and have aggregations switched off only for the flat view, we kindly suggest the following workaround:
 
1. Remove aggregation buttons from the measures in the Field List
 
   1. Listen to the fieldlistopen event, which triggers when the Field List is opened.
   2. Then, use the getOptions() API call to check if the type of the grid is flat.
   3. The aggregation buttons can be found, for example, by class name:

document.querySelectorAll(".fm-aggr-display");

   4. There is more than one approach of hiding the HTML elements from JavaScript code. 
       For example, you can remove them using the built-in JavaScript remove() function.
 
We have prepared a JSFiddle sample for visualization: https://jsfiddle.net/flexmonster/ce51w8ky/
Please note that this example demonstrates a general approach, which can be further customized.
 
2.(optional) If the context menu is enabled in your project, we also need to remove the aggregations from the context menu.
   1. Add the customizeContextMenu function to your Flexmonster object as follows:

new Flexmonster({
   container: "pivot-container",
   customizeContextMenu: customizeContextMenuFunction,
   report: {
     ...
   },
   ...
});

 
   2. Then, remove the Aggregations from the array of items shown in the context menu:

function customizeContextMenuFunction(items, data, viewType) {
  if (viewType == "flat") {
    return items.filter(item => item.id !== "aggregation");
  }
}

   You can read more about customizing the context menu in our docs: https://www.flexmonster.com/doc/customizing-context-menu/.
 
Hope you will find our answer helpful.
 
Regards,
Solomiia

Public
raviteja October 27, 2022

Hi Solomiia,
 
The first solution works for my requirement.
Thank you 🙂

This question is now closed