cancel
Showing results for 
Search instead for 
Did you mean: 
Community_Admin
Community Team Member
Community Team Member

Question:

Viewers don't have the ability to show and hide grand totals which I want them to be able to do. Is it possible to achieve with Blox functionality?

Answer:

The pivot widget's "style" attribute includes settings for grand totals, and you can turn them on and off that way.  Here's what we did:
1. We created a new custom BloX action, called "ShowOrHideGrandTotals," using the below script:
var oidArray = payload.oidArray;
 //the oids of the pivot widget you want to modify; an array
 var toggleAction = payload.toggleAction;
 //can be either "show" or "hide"
 var toggleType = payload.toggleType;
 //can be either "row" or "column" or "both"

if (toggleAction === "show") {
    var toggleValue = true;
} else if (toggleAction === "hide") {
    var toggleValue = false;
}

//modify each widget you want to change

var i = 0;
for (; i < prism.activeDashboard.widgets.$$widgets.length; i++) {
    if (oidArray.includes(prism.activeDashboard.widgets.$$widgets[i].oid)) {
        if (toggleType === "row") {
            prism.activeDashboard.widgets.$$widgets[i].style.rowsGrandTotal = toggleValue;
            prism.activeDashboard.widgets.$$widgets[i].refresh();
        } else if (toggleType === "column") {
            prism.activeDashboard.widgets.$$widgets[i].style.columnsGrandTotal = toggleValue;
            prism.activeDashboard.widgets.$$widgets[i].refresh();
        } else if (toggleType === "both") {
            prism.activeDashboard.widgets.$$widgets[i].style.columnsGrandTotal = toggleValue;
            prism.activeDashboard.widgets.$$widgets[i].style.rowsGrandTotal = toggleValue;
            prism.activeDashboard.widgets.$$widgets[i].refresh();
        }
    }
}​
2. We then created the action snippet below, and hit the "create" button to finish creating our own custom action.
{
    "type": "ShowOrHideGrandTotals",
    "title": "title",
    "oidArray": [],
    "toggleAction": "",
    "toggleType": ""
}​
As you can see, for each button you enter four pieces of information: 
  • the title of the button
  • the OIDs for each pivot widget you want the action to modify
  • the action to take (either "show" or "hide")
  • and the type of action, e.g. what's being shown or hidden ("row", "column", or "both").
3. Ww created a BloX widget to test this new custom action on some pivot tables.  Here's the JSON from the "Editor" tab (with the real widget OIDs removed):
{
    "style": "",
    "script": "",
    "title": "",
    "showCarousel": true,
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "ActionSet",
                    "actions": [
                        {
                            "type": "ShowOrHideGrandTotals",
                            "title": "Show Grand Totals",
                            "oidArray": [
                                "widgetOID1",
                                "widgetOID2"
                            ],
                            "toggleAction": "show",
                            "toggleType": "both"
                        },
                        {
                            "type": "ShowOrHideGrandTotals",
                            "title": "Hide Grand Totals",
                            "oidArray": [
                                "widgetOID1",
                                "widgetOID2"
                            ],
                            "toggleAction": "hide",
                            "toggleType": "both"
                        }
                    ]
                }
            ]
        }
    ],
    "actions": []
}​

Here's a screenshot of that widget and the dashboard as a whole.

Community_Admin_0-1634569253896.png

In our test case, as you can tell from the BloX template above, the "Show Grand Totals" button displays the grand totals for both columns and rows (you can see the column totals on the right of the image), and the "Hide Grand Totals" button hides both of them.

Hope this helps in achieving your goal!

Rate this article:
Version history
Last update:
‎11-10-2023 12:31 PM
Updated by: