When creating a dashboard, there are several filter objects to implement. They can be used to limit your data and to display data for a specific value.
Sometimes, it is desired to initialize a filter for certain values so that the dashboard shows only that specific data when opening it. This is possible by using filter initialization option. As explained in this article you can set up such filter initialization from inside the editor or on the token. Setting this up via the token allows you to set a different selection based on the specific user looking at the dashboard. This may be particularly interesting when the values available are different per user.
After creating a filter or chart dashboard item, you can set default values by activating filter initialization. First, select the value(s) you want to use as the default — either directly in the filter widget or by selecting the data point(s) in a chart. Next, open the dashboard item’s settings by clicking the settings icon when hovering over the item. This will open the item settings panel:
Switching initialization on saves your current selection as the default; switching it off removes any previous initialization. Once enabled, the initialized selection will automatically apply the next time the dashboard is opened 🎉
When embedding a dashboard, you can set an initialization filter dynamically by adding them to your request for a embed authorization token. The following code snippet will set an intialization filter on a filter object, below you can find specific guides for the different filter widget types:
Guides to setting dynamic initialization filter options for:
const Luzmo = require('@luzmo/nodejs-sdk');
var client = new Luzmo({
api_key: '< Your API key >',
api_token: '< Your API token >'
});
client.create('authorization', {
type: 'embed',
username: '12345678',
suborganization: 'Burrito Co.',
name: 'embed user',
email: 'embed_user@example.com',
access: {
collections: [
{
id: '<collection ID>',
inheritRights: 'use'
}
]
},
// Add a initialization filter
filters: [
{
clause: 'where',
origin: 'initialization',
chart_id: '< chart id of a filter object contained in the dashboard >',
expression: ' <expression> ',
value: '< value to be applied to the expression >'
}
]
}).then((result) => {
/*
The embed authorization key and token can be found in result.id and result.token, respectively.
The specified filters can be found in result.filters.
*/
console.log(result);
});
If you want to initialize a chart with a certain selection, you should specify the chart id that you'd like to initialize with a filter as well as the dataset_id and column_id. The following code snippet shows this:
const Luzmo = require('@luzmo/nodejs-sdk');
var client = new Luzmo({
api_key: '< Your API key >',
api_token: '< Your API token >'
});
client.create('authorization', {
type: 'embed',
username: '12345678',
suborganization: 'Burrito Co.',
name: 'Embed user',
email : 'embed_user@example.com',
access: {
collections: [
{
id: '<collection ID>',
inheritRights: 'use'
}
]
},
// Add a initialization filter
filters: [
{
clause: 'where',
origin: 'initialization',
chart_id: '< chart id of a chart object contained in the dashboard >',
column_id: '< column id of the column you would like to apply the initialization filter to >',
securable_id: '< dataset id of the dataset containing the column specified >',
expression: '? = ?',
value: '< value to be applied to the expression >'
}
]
}).then((result) => {
/*
The embed authorization key and token can be found in result.id and result.token, respectively.
The specified filters can be found in result.filters.
*/
console.log(result);
});
All details about the setting initialization filters when creating a embed authorization token, together with some code examples, can be found in our Developer documentation.