Need a special offer?Find out if your project fits.
+
All documentation
  • Introduction
  • Connecting to Data Source
  • Browser compatibility
  • Documentation for older versions
  • Using methods and events

    This guide explains how to use Flexmonster methods and events. First, we will get a reference to the Flexmonster instance. Then we will use this reference to call methods and subscribe to events.

    Prerequisites

    • An application with Flexmonster embedded into it.
      If Flexmonster is not yet embedded, see Integrating Flexmonster.

    Get a reference to the Flexmonster instance

    To interact with Flexmonster via its API, you need a reference to the Flexmonster instance. Get the reference during or after the initialization:

    During the initialization

    When calling the new Flexmonster() constructor, assign its result to a variable:

    const pivot = new Flexmonster({
      // …
    });

    After the initialization

    Get the reference to the Flexmonster instance via the uielement property of the component’s container:

    const pivot =
      document.getElementById("flexmonsterContainer").uielement.flexmonster;

    Now the pivot variable contains a reference to the Flexmonster instance. Use the pivot to access Flexmonster API.

    Use methods

    Call Flexmonster methods using the reference to the Flexmonster instance:

    pivot.setReport(report);

    Some methods can also be defined as Flexmonster initialization parameters:

    const pivot = new Flexmonster({
      // …
      customizeCell: customizeCellFunction
    });

    Such methods include:

    See the full list of Flexmonster methods.

    Use events

    There are two ways to subscribe to an event:

    You can also unsubscribe from an event.

    Subscribing to an event via the initialization parameters

    Define an event as the new Flexmonster() parameter and assign an event handler to it:

    const pivot = new Flexmonster({
      // …
      reportcomplete: onReportComplete
    });

    See the full list of Flexmonster events.

    Subscribing to an event via the on() method

    Call the on() method using the reference to the Flexmonster instance:

    pivot.on('reportcomplete', onReportComplete);

    Check out the full list of Flexmonster events.

    Unsubscribing from an event

    Use the off() method to unsubscribe from an event:

    pivot.off('reportcomplete');

    This will remove all handlers from the event. To remove a specific handler, pass its name as a second parameter to off():

    pivot.off('reportcomplete', onReportComplete);

    Note If a handler is specified as an anonymous function, you can remove it only by removing all handlers.

    See also