Handling Widget Lifecycle and Data Binding

Objective

After completing this lesson, you will be able to implement lifecycle handling and connect a custom widget to an SAP Analytics Cloud data model using data binding.

Integrate Lifecycle Function

SAP Analytics Cloud controls the lifecycle of a custom widget. Lifecycle functions are invoked when the widget is updated, resized, or destroyed. These functions are called custom widgets lifecycle functions, such as:

  • onCustomWidgetResize
  • onCustomWidgetBeforeUpdate
  • onCustomWidgetAfterUpdate
  • onCustomWidgetDestroy

Whenever the state of the widget changes (for example, size, properties, or data), SAP Analytics Cloud triggers specific lifecycle functions in the Web Component.

Exercise

In this exercise, you will implement selected lifecycle functions and observe how the widget reacts when its size changes.

You will:

  1. modify the main.js file to add lifecycle handling to the custom widget
  2. upload the custom widget to SAP Analytics Cloud
  3. test the widget by changing its size

Result

The widget reacts correctly to lifecycle events triggered by SAP Analytics Cloud.

Add Data Binding

Data binding enables a custom widget to access data from a data model. It connects the widget to dimensions and measures selected in the Builder Panel.

To enable data binding, both:

  • the metadata (JSON), and
  • the JavaScript implementation must be updated.

Exercise

In this exercise, you will configure data binding and display the bound data inside the custom widget.

You will:

  1. modify the main.js and index.json files
  2. upload the files to SAP Analytics Cloud
  3. set up data binding for a custom widget via the Builder Panel
  4. see the bound data displayed within the custom widget

Result

The custom widget receives and processes data from an existing data model within SAP Analytics Cloud.

Summary

Custom widgets react to lifecycle events triggered by SAP Analytics Cloud, such as resizing or updates.

By implementing lifecycle methods, developers control when and how the widget updates.

Data binding connects the widget to an SAP Analytics Cloud data model, enabling it to access and display structured data.