Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

The custom widgets JavaScript API provides a number of properties and methods. Some of these are mostly used to access data, but others are explicitly provided as extension points to overwrite.

Table of Contents

Table of Contents
outlinetrue
excludeTable of Contents

...

The options for each composed widget depend on the widget type. If a widget requires one or more facets to visualize, the facets configuration should be passed in as shown in example above.

Widgets.Search

Rendering

itemTemplate

Specifies that a custom HTML template for each item should be used instead of the default one. Any of the custom templates uploaded with the custom widget can be assigned to this property directly.

Expand
titleExample
Code Block
languagejs
titleExample
afterInitialize: function () {
	this.itemTemplate = this.customTemplates['myTemplate.html'];
},

getItemTemplateParams

widget.getItemTemplateParams()

If implemented, and if itemTemplate is defined, the returned value of getItemTemplateParams() will be passed onto the HTML side.

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

set()

Dashboard State

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

...

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

set()

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

...