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.

Static filter initialization via the editor

After creating a filter, you can fix the values by activating the filter initialization. To do so, click on the setting icon of the filter object.

At the right hand side, the item settings section will open. There, you will find the option to turn the initialization on. Here, you can activate it for the current filter or remove the previous one.

The initialized filter will be applied immediately when opening the dashboards next time, as you can see in the example below.

Dynamic filter initialization via the embed Authorization token

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.

Need more information?

Do you still have questions? Let us know how we can help.
Send us feedback!