Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix documentation for dashboard store

...

A Backbone.js model that represents the currently rendered dashboard. See dashboard statestore for the main usage of this model.

...

Expand
titleExample

This is an example that extends the facets table with an additional click handler.

Code Block
languagejs
return Widgets.FacetsTable.extend({
    customEvents: {
        'click tr': 'onRowClicked',
    },
 
    onRowClicked: function () {
        this.dashboard.statestore.set({'additionalInfo': true});
    },
});

See dashboard statestore for information on the state store property being used here.

...

onStoreChange

widget.onStateChangeonStoreChange(model, options)    

Status
colourBlue
titleExtend

Called when a state store variable changes (see Dashboard StateStore).

The model argument can be used to access the exact property or properties that have changed by accessing model.changed. That property is a hash containing all the attributes that changed in the last set call.

...

Expand
titleExample
Code Block
languagejs
getItemTemplateParams: function () {
    return {
		external_id: 1234,
	};
},


Dashboard

...

Store

The dashboard state store is accessible in the widget using the widget.dashboard.state propertystore property (usually this.dashboard.store). This model is the recommended way for custom widgets to talk to each-other. The dashboard state store is a Backbone.js model though without persistence.

Custom widgets should implement the onStateChange onStoreChange method to listen for changes to the statestore.

Architecture

A good example for when to use the state store is when there are two widgets on a dashboard that have to communicate with each-other.

For example a navigation widget can be implemented which presents the user with a number of menu options. When clicking on one of the options, the state store is updated by setting a attribute. A second widget reacts to that state store value and changes the content to be displayed depending on the set attribute.

Methods

get()

statestore.get(attribute)

Get the current value of the state store attribute.

Expand
titleExample
Code Block
languagejs
onStateChangeonStoreChange: function () {
    if (this.dashboard.statestore.get('additionalInfo')) {
        this.$el.addClass('additional-info-requested');
    }
},

set()

statestore.set(attribute, value)
statestore.set(attributes)

Set one attribute to the given value or - in the secondary form - update all the key/value pairs from the hash.

If any attribute changes, a change event is triggered. The easiest way to subscribe to those in the widget is by implementing the onStateChange onStoreChange method.

Expand
titleExample
Code Block
languagejs
onRowClicked: function () {
    this.dashboard.statestore.set({'additionalInfo': true});
},

...