close

Filter

loading table of contents...

Studio Developer Manual / Version 2404

Table Of Contents

9.19.4.3 Custom Widget State Class

In many cases, it is not necessary to create your own widget state class for your custom widget type. As shown earlier in this chapter, the predefined class WidgetState allows you to set the dashboard column, the widget type and the widget's rowspan. This is sufficient unless you want to put widgets of your type into the default dashboard and at the same time use a configuration other than the default. However, if you want to do just that, CoreMedia recommends that you create your own widget state class as an extension to WidgetState. For the simple search widget, the custom state class SimpleSearchWidgetState looks as follows:

import Config from "@jangaroo/runtime/Config";
import ConfigUtils from "@jangaroo/runtime/ConfigUtils";
import WidgetState from "@coremedia/studio-client.main.editor-components/sdk/dashboard/WidgetState";
import SimpleSearchWidget from "@coremedia/studio-client.main.editor-components/sdk/dashboard/widgets/search/SimpleSearchWidget";

class SimpleSearchWidgetState extends WidgetState {
  /**
   * The search text that is used for the collection view.
   * Default "".
   */
  searchText: string = null;
  /**
   * The content type that is used in the content type filter.
   * Default "Document_".
   */
  contentType: string = null;
  /**
   * Whether to restrict the search to the preferred site.
   * Default true.
   */
  preferredSite: boolean = false;

  constructor(config: Config<WidgetState>) {
    super(ConfigUtils.apply(Config(SimpleSearchWidgetState, { widgetTypeId: SimpleSearchWidget.xtype }), config));
  }
}

export default SimpleSearchWidgetState;

Example 9.79. widget State Class for Simple Search widget


This class allows you to launch simple search widgets initially with the configuration properties searchText and contentType being set. They are set via the dashboard configuration prior to the dashboard's launch instead of being set by the user via the SimpleSearchWidgetEditor component at runtime (although this is of course possible afterwards).

The widgetTypeId for the SimpleSearchWidgetState is set to the xtype of SimpleSearchWidget. This is because widget types that extend ComponentBasedWidgetType by default take the xtype of their widget component as their id.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.