With a few lines of Groovy code, it is very easy to embed a dashboard as a portlet of another dashboard. This creates an interactive dashboard which can change dynamically in reaction to an event. Clicking on a result in one portlet triggers an event, which changes the input (and therefore the content) of another, embedded portlet.
For example, you have a dashboard with a grid, which contains details about products, and a chart that graphically displays the product data. When you select a row in the grid (a particular product), you want to see the chart automatically updated so that it displays the correct data for the selected product.
In this section:
See also an example How to Create an Interactive Embedded Dashboard.
Advantages
The main reasons for using embedded dashboards are:
-
A single dashboard can be reused by embedding it within multiple main dashboards.
-
An embedded dashboard can be based on events and parameters provided by the main dashboard.
Code
Add a logic element that returns a new DashboardApi instance:
DashboardApi example
return api.dashboard("MyEmbeddedDashboard")
.showEmbedded()
Of course, it is also possible to add more elements in the main dashboard.
Parameters
The main dashboard can provide input parameters to the embedded dashboard via DashboardApi.setParam(String param_name, Object param_value). The above example can be extended to:
Main Dashboard
return api.dashboard('SalesDetailEmbedded')
// Param values are sent to the embedded dashboard as it's inputs.
// Value of parameter 'customerId' will be accessible in the embedded dashboard using 'input.customerId'
.setParam('customerId', 'CD-00067')
// You can also forward value of an input
.setParam('sku', input.sku)
// Ensure the dashboard is embedded
.showEmbedded()
// You will probably want to hide the embedded dashboard's inputs from the end user
.withInputsHidden()
The embedded dashboard can then read the parameters via the input binding variable:
Embedded Dashboard
def sku = input.sku
def customerId = input.customerId
// these can now be used, e.g. to build a chart
api.newChartBuilder().newBarLine().addSeries()
.setLabel('Invoice Price p/u')
.setDatamart('DM.SalesTransactions')
.setCurrency('EUR')
.addDimFilter('ProductID', sku)
.addDimFilter('CustomerID', customerId)
.setAxisX('Country')
.setAxisY('InvoicePrice').withPerUnit().back()
.setType(SeriesType.BAR)
.withSortByAxisY(SortType.ASCENDING)
.back()
.build()
Events
Some UI objects can trigger events that are sent to the embedded dashboard:
Event can hold data (e.g., values of grid columns), which are passed to the dashboard.
ResultMatrix
The ResultMatrix element can trigger an event for the embedded dashboard to receive new inputs and to recalculate.
The event is triggered by a row click from the user. To pass cell values from the matrix, use withColValueAsEventDataAttr() for each column for which values should be added as a payload of the event. Only single selections of grid rows are supported.
Main Dashboard - Matrix Element
def matrix = api.newMatrix()
.withColumnFormats([
"Country" : FieldFormatType.TEXT,
"ProductID": FieldFormatType.TEXT,
])
.wihtRows(...)
// Events are globally shared between browser tabs and they are not limited only to dashboards.
// This API creates an event that is tight to the current dashboard only:
def eventName = api.dashboardWideEvent('MyEventName')
matrix.onRowSelection().triggerEvent(eventName)
// Value from a column will be stored using the same name
.withColValueAsEventDataAttr("Country", "Country")
// Value from a `ProductID` column will be stored in the event as `sku` property
.withColValueAsEventDataAttr("ProductID", "sku")
return matrix
Main Dashboard - Embedded Dashboard Element
def eventName = api.dashboardWideEvent('MyEventName')
return api.dashboard('MyEmbeddedDashboard')
// Pass a common value
.setParam("Date", input.Date)
.showEmbedded()
.andRecalculateOn(eventName)
// Event property `sku` will be accessible using `input.sku`
.withEventDataAttr("sku").asParam("sku")
.withEventDataAttr("Country").asParam("Country")
The embedded dashboard's logic can read the parameters as input.<param_name1>) and input.<param_name2>.
Open Embedded Dashboard on New Tab
An embedded dashboard can be opened as a separate dashboard in a new browser tab. Input valus are passed in the URL.
Embedded Element
def eventName = api.dashboardWideEvent('MyEventName')
return api.dashboard('MyEmbeddedDashboard')
.setParam("Date", input.Date)
.showEmbedded()
.openInTabOrRecalculateOn(eventName)
.withEventDataAttr("sku").asParam("sku")
.withEventDataAttr("Country").asParam("Country")
ScatterChart
A chart generating click events that can send parameters and refresh an embedded dashboard is the ChartBuilder's ScatterChart.
It is possible to get both the AggregationBy (i.e., GroupBy) and BandBy dimensions of the clicked point.
Main Dashboard - Chart Element
def eventName = api.dashboardWideEvent('MyEventName')
def scatter = api.newChartBuilder().newScatter()
scatter.getOptions()
.setTitle('Title')
.setDisableDrilldown(true)
// etc.
scatter.addSeries()
.setLabel('Series1')
// etc.
scatter.onClick()
.triggerEvent(eventName)
.withAggregationByAsEventDataAttr() // attribute_name = 'aggregationBy'
.withBandByAsEventDataAttr() // attribute_name = 'bandBy'
Main Dashboard - Embedded Element
def eventName = api.dashboardWideEvent('MyEventName')
return api.dashboard("MyEmbeddedDashboard")
.showEmbedded()
.andRecalculateOn(eventName)
.withEventDataAttr('aggregationBy').asParam("aggregationBy")
.withEventDataAttr('bandBy').asParam("bandBy")
The embedded dashboard's logic can read the parameters using input.aggregationBy and input.bandBy.
BarLineChart
Another chart that can generate click events is the ChartBuilder's BarLineChart.
The only data provided so far is the X axis category of the clicked bar.
Main Dashboard - Chart Element
def eventName = api.dashboardWideEvent('MyEventName')
def barChart = api.newChartBuilder().newBarLine()
barChart.getOptions()
.setTitle('Title')
.setDisableDrilldown(true)
// etc.
barChart.addSeries()
.setLabel('Series1')
// etc.
barChart.onClick()
.triggerEvent(eventName)
.withXAsEventDataAttr() // attribute_name 'x'
Main Dashboard - Embedded Element
def eventName = api.dashboardWideEvent('MyEventName')
return api.dashboard("MyEmbeddedDashboard")
.showEmbedded()
.andRecalculateOn(eventName)
// expose the event payload
.withEventDataAttr('x').asParam('x')
The embedded dashboard's logic can read the parameter as input.x.
Data Tab of any Chart (except Waterfalls)
Mainly with the DataTable chart (but also with the Data tab of any other chart type except Waterfall and WaterfallComparison), it is possible to subscribe to row level and cell level click events. The event can provide values of some or all of the dimensions shown in the grid, by calling one of these methods:
-
withAnyDimensionAsEventDataAttr()as a wildcard -
withDimensionAsEventDataAttr(<dimName>)one or multiple times
For row click events all the requested dimensions will be provided. For cell clicks, the cell must be in the column of a subscribed dimension, and if so then only the cell's contents will be provided.
Main Dashboard - Chart Element
def eventName = api.dashboardWideEvent('MyEventName')
def table = api.newChartBuilder().newDataTable()
table.getOptions()
.setTitle('Title')
.setDisableDrilldown(true)
// etc.
table.addSeries()
.setLabel('Series1')
// etc.
table.onRowClick()
.triggerEvent(eventName)
.withDimensionAsEventDataAttr(<dimension_name1>) // attribute_name = dim_name
.withDimensionAsEventDataAttr(<dimension_name2>) // attribute_name = dim_name
...
// or .withAnyDimensionAsEventDataAttr() or .withDimensionAsEventDataAttr('*')
table.onCellClick()
.triggerEvent(eventName)
.withDimensionAsEventDataAttr(<dimension_name1>) // attribute_name = dim_name
.withDimensionAsEventDataAttr(<dimension_name2>) // attribute_name = dim_name
...
// or .withAnyDimensionAsEventDataAttr() or .withDimensionAsEventDataAttr('*')
Main Dashboard - Embedded Element
return api.dashboard('<dashboard_name>').showEmbedded()
.andRecalculateOn(eventName)
// expose the event payload
.withEventDataAttr(<dimension_name1>).asParam(<param_name1>)
.withEventDataAttr(<dimension_name2>).asParam(<param_name2>)
...
The embedded dashboard's logic can read the parameters as input.<param_name1> and input.<param_name2>.
Dashboard Display Modes
There are three ways to display the dashboard:
-
Embedded – The dashboard is embedded in the master dashboard as another portlet/dashlet.
-
Tab – The dashboard is opened in a new tab.
-
Window – The dashboard is opened in a new popup window.
Available Dashboard API Methods
-
DashboardApi setParam(String paramName, Object value); -
DashboardApi showEmbedded(); -
DashboardApi andRecalculateOn(String eventName); -
DashboardApi openInTabOrRecalculateOn(String eventName); -
DashboardApi openInModalOrRecalculateOn(String eventName); -
DashboardApi withEventDataAttr(String attrName); -
DashboardApi asParam(String paramName); -
DashboardApi withInputsHidden();
For more details see the API Documentation.