Script to Collapse all, has any one done this is it possible

My user wants one button that collapses multiple "Row Header Columns" at once instead of having to collapse each one individually.

They want that data there but want it out of the way in some cases and then see it for detail.


I have explored the api but have not found any public (non underscored) ways to collapse and expand.


Hello James,


The “Collapse All” is a metric set setting found in the data analysis panel. You can override many different metric set settings using JavaScript while viewing a dashboard using the request overrides. For this particular case, you can use the retrieveAllMemberOnly on the hierarchy overrides.

If you need to reference how this is implemented on a dashboard, you can go to our Script Library on our support site. Below is a sample of how to set metric set overrides via scripting. At line 101 of the sample, it shows how to implement the retrieveAllMemberOnly on a specific hierarchy.


You can collapse as many hierarchies you want, as long as you define a new override for the hierarchy inside the metric set, and push that override.


In the example below, I have two hierarchies with the unique names DueDate and TerritoryID; I created two hierarchy overrides to be pushed on the click action of a button. The result of this script is when I click the button, both hierarchies defined inside my overrides are collapsed.


Script:

var view = this.parentView;

var requestOverrides = new dundas.data.RequestOverrides();

var hierarchyOverride1 =

new dundas.data.RequestHierarchyOverrides(

{

retrieveAllMemberOnly: true,

uniqueName: 'DueDate'

}

);

var hierarchyOverride2 =

new dundas.data.RequestHierarchyOverrides(

{

retrieveAllMemberOnly: true,

uniqueName: 'TerritoryID'

}

);

requestOverrides.hierarchyOverrides.push(hierarchyOverride1);

requestOverrides.hierarchyOverrides.push(hierarchyOverride2);


// Get the metric set binging override.

var metricSetBindingOverride =

view.control.overrides.getMetricSetBindingOverrideById(table1.id, table1.metricSetBindings[0].id);


if (metricSetBindingOverride)

{

// Update the existing override.

metricSetBindingOverride.requestOverrides = requestOverrides;

}

else

{

// Add new override as one doesn't exist.

view.control.overrides.metricSetBindingOverrides.push(

{

adapterId: table1.id,

metricSetBindingId: table1.metricSetBindings[0].id,

requestOverrides: requestOverrides

}

);

}

// Call load data on the adapter.

var dataLoadPromise = table1.loadData();

1 Like

Thanks it working great now.

Thank you! To contribute back to this:

If you want to run this from the ‘ready’ for the dashboard, like I did (so that all columns start out as collapsed), then you’ll need to change the first line:

var view = this;

since there is no parentView in this scope.

Otherwise, this worked perfectly.

Also, setting the values to false reverts to full expansion of the columns.

1 Like

I’ve just used this today and it works perfectly.

Only issue I have is that the ‘unknown’ member now cannot expand. Is there any way that the unknown member can work the same as the known ones?

Thanks

are you filling it at the cube level or metric set level? I started filling nulls at the cube level and it allows for filtering, sorting, expansion, etc.

1 Like

Thanks @ken. That worked.

1 Like