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.
To interact with Flexmonster via its API, you need a reference to the Flexmonster instance. Get the reference during or after the initialization:
When calling the new Flexmonster() constructor, assign its result to a variable:
const pivot = new Flexmonster({
// …
});
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.
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.
There are two ways to subscribe to an event:
You can also unsubscribe from an event.
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.
Call the on() method using the reference to the Flexmonster instance:
pivot.on('reportcomplete', onReportComplete);Check out the full list of Flexmonster events.
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.