This guide explains how to use Flexmonster methods and events in a Blazor application. First, we will get a reference to the Flexmonster instance. Then we will use this reference to call methods and subscribe to events.
To call methods and subscribe to events, we will need a reference to the Flexmonster instance. Create the reference and attach it to the FlexmonsterComponent as follows:
<FlexmonsterComponent @ref="flexmonster"
...
/>
@code {
private FlexmonsterComponent flexmonster;
}
We can now reference the Flexmonster instance throughout the Blazor component.
To call Flexmonster’s methods, use a reference to the Flexmonster instance:
<FlexmonsterComponent @ref="flexmonster"
...
/>
@code {
private FlexmonsterComponent flexmonster;
private async Task ShowMyChart() {
await flexmonster.ShowCharts("pie");
}
}
Notice that method names in Blazor are pascal-cased (i. e., ShowCharts instead of showCharts) to conform to C# code conventions.
Find more examples of using Flexmonster’s methods in the sample Blazor project.
Most of Flexmonster’s methods work in Blazor just like in plain JavaScript. However, the following methods have certain usage specifics:
callbackHandler parameter is available only for CSV and HTML exports.Besides, some API calls are not available in Blazor natively. However, you can still use them through JavaScript if needed:
You can subscribe to events:
For details on unsubscribing from events, see this section.
When initializing the FlexmonsterComponent, you can subscribe to events using component parameters:
<FlexmonsterComponent OnReportComplete="@ReportCompleteHandler"
...
/>
@code {
// Other code
private async Task ReportCompleteHandler() {
// Do something
}
}
Notice that parameter names in Blazor are different from event names in Flexmonster:
On at the beginning.Consider these differences when subscribing to events via component parameters. For example, specify OnReportComplete instead of reportcomplete.
You can subscribe to events on the fly using a reference to the FlexmonsterComponent. Attach your event handler to a Flexmonster’s event with the += operator:
<FlexmonsterComponent @ref="flexmonster"
...
/>
@code {
private FlexmonsterComponent flexmonster;
private void SubscribeToEvent() {
flexmonster.OnReportCompleteEvent += ReportCompleteHandler;
}
private async Task ReportCompleteHandler() {
// Do something
}
}
Note We do not recommend using anonymous event handlers, since there are specifics in unsubscribing from them.
Notice that event names in Blazor are different from the ones in Flexmonster:
On at the beginning.Event at the end.Consider these differences when subscribing to events via the reference to Flexmonster. For example, specify OnReportCompleteEvent instead of reportcomplete.
For more examples of subscribing to the events, see the sample Blazor project.
To remove an event handler, use the -= operator:
@code {
// Other code
private void UnsubscribeFromEvent() {
flexmonster.OnReportCompleteEvent -= ReportCompleteHandler;
}
}Most of Flexmonster’s events work in Blazor just like in plain JavaScript. However, the following events have certain usage specifics:
drillthroughopen event handler, you should manually cast the object to the CellDataObject or ChartDataObject. It can be done as follows:
private async Task OnDrillThroughOpenHandler(object obj)
{
if (obj is CellData)
{
var casted = (CellData) obj;
}
else
{
var casted = (ChartData) obj;
}
}
Besides, some events are not available in Blazor natively. However, you can still use them through JavaScript if needed:
Can't find your answer?
Visit the FAQ
Flexmonster Pivot Table & Charts is a JavaScript pivot table component for adding interactive reporting and data analysis to web applications. Users can summarize, filter, sort, and explore data in pivot tables and charts, drill into results, and export reports.
Flexmonster works in plain JavaScript and TypeScript projects. It also integrates with React, Next.js, Angular, Vue, Blazor, and other technologies. See all integration options.
Flexmonster supports JSON and CSV files, SQL databases, MongoDB, Elasticsearch, and Microsoft Analysis Services (SSAS). You can also connect other data sources through your own backend. See supported data sources.
Flexmonster offers licenses for internal corporate use, SaaS products, and OEM distribution. Pricing varies by license and plan. SaaS projects can also use the free SaaS Entry license during development. Learn more on the pricing page.
Yes. Flexmonster offers a 30-day free trial that lets you evaluate all its features. No credit card is required. The trial version has a watermark.
To get started with Flexmonster, follow our integration guide.