UPD: Applies to the versions of FastCube .NET before 2022.1. License packages are now available on our NuGet server.
The ReactJs library has become widespread in the web development of single-page applications. Previously we have covered how to display reports and the online report designer in React SPA application. Now it is possible to display cubes and slices of data from FastCube.Core on a web page. Let's consider how to do this.
To create an ASP .NET Core app with a React frontend part, you can use a template in the .NET SDK. Run in the command line:
This command will create a demo application that we can use to display the cube. Of course, for this, you must have the .NET Core SDK installed. In addition, the application will require Node.js.
Go to the directory of the created application:
Let's start working with the created web application. First, let’s install the FastCube packages. Open the Nuget package manager. In the upper right corner of the window, you will see a gear icon, which opens the settings of package sources. Click on it and add a new package source - a folder with our FastCube packages, which are located in the C:\Program Files (x86)\FastReports\FastCube.Net Professional\Nuget folder.
Select the added package source in the drop-down list and install the packages:
We connect FastCube in the Startup.cs file, add the code in the Configure () method:
Our application already contains WeatherForecastController. Let's add our web method to it:
The Cube and Slice objects are related because, in fact, the slice is part of the cube. A WebGrid object is used to display an interactive crosstab. It can display both a WebCubeGrid slice and a WebSliceGrid cube. In our example, we loaded the cube that we previously created in the FastCube .NET desktop version.
Pay attention to the class from which the controller inherits. It should be Controller, not BaseController.
Now let's create a view for this method. This can be done by right-clicking on the ShowCube method signature. The view will contain a single line of the code:
Now let's move on to SPA application, which is located in the ClientApp folder. We need to add our component to the src->components folder. It will display the iframe with the view we created above. Add the Cube.js file with the following code:
Everything is easy here. We display iframe that refers to a method in the controller.
Now you need to add the component to the App.js application structure:
In addition, you need to add a new menu item in the NavMenu.js file:
The application is ready. Let's run it:
Thus, you can display your web cube using FastCube.NET in a React SPA application.