logo
small logo
  • Ürünler
  • Satın al
  • Yardım
  • About
  • Kullanıcı paneli Yardım
    • en
    • de
    • JP
    • ZH
  • Anasayfa
  • /
  • Articles
  • /
  • How to use FastCube .NET in React application
  • How to use Online Designer in ASP .NET Core

    17 Ocak 2018

    One of the novelties by FastReport .NET 2018 was the adaptation of OnlineDesigner to the

    read more
  • FastReport .NET packages and .NET 5.0

    17 Aralık 2020

    UPD: Applies to the versions of FastReport .NET before 2022.2. License packages are now available

    read more
  • How to create the invoice from ASP.Net Core application

    31 Ağustos 2020

    Few believed in the success of the new open-source ASP.Net Core framework from Microsoft. It’s

    read more
  • How to create business cards from ASP .Net Core application

    31 Mayıs 2020

    ASP.Net Core Framework is a cross-platform solution for creating web applications. This means that you

    read more
  • How to upload a report to OnlineDesigner and download it after editing in an ASP .NET Core application

    30 Haziran 2019

    While working with Fast Reports online report designer, we usually have to upload our report

    read more

How to use FastCube .NET in React application

1 Ekim 2021

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:

dotnet new react -o MyReactApp

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:

cd MyReactApp

and install javascript packages using the command:

npm install

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.

Configuring a local package source

Select the added package source in the drop-down list and install the packages:

Installing FastCube Core packages

We connect FastCube in the Startup.cs file, add the code in the Configure () method:

app.UseFastCube();

Our application already contains WeatherForecastController. Let's add our web method to it:

[HttpGet("[action]")]
 public IActionResult ShowCube()
 {
 Cube cube = new Cube();
 Slice slice = new Slice()
 {
 Cube = cube
 };
 FilterManager filterManager = new FilterManager()
 {
 Cube = cube
 };
 WebGrid grid;
 grid = new WebSliceGrid()
 {
 Slice = slice
 };
 
 ViewBag.WebGrid = grid;
 
 cube.SourceType = SourceType.File;
 cube.Load(Path.Combine("C:\\Users\\FR\\Downloads\\fastcube-net-master\\Demos\\Data\\", "Cubes", "calculated_measures.mdc")); return View(); }

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:

@await ViewBag.WebGrid.Render()

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:

import React, { Component } from 'react';
export class Cube extends Component {
 static getCube() { 
 return { __html: '<iframe width="1000" height="1000" src="weatherforecast/ShowCube" />' };
 }
 render() {
 return (
 < div dangerouslySetInnerHTML={Cube.getCube()} />
 );
 } 
}

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:

import React, { Component } from 'react';
import { Route } from 'react-router';
import { Layout } from './components/Layout';
import { Home } from './components/Home';
import { FetchData } from './components/FetchData';
import { Counter } from './components/Counter';
import { Cube } from './components/Cube';
 
import './custom.css'
 
export default class App extends Component {
 static displayName = App.name;
 
 render () {
 return (
 <Layout>
 <Route exact path='/' component={Home} />
 <Route path='/counter' component={Counter} />
 <Route path='/fetch-data' component={FetchData} />
 <Route path='/cube' component={Cube} />
 </Layout>
 );
 }
}

In addition, you need to add a new menu item in the NavMenu.js file:

import React, { Component } from 'react';
import { Collapse, Container, Navbar, NavbarBrand, NavbarToggler, NavItem, NavLink } from 'reactstrap';
import { Link } from 'react-router-dom';
import './NavMenu.css';
 
export class NavMenu extends Component {
 static displayName = NavMenu.name;
 
 constructor (props) {
 super(props);
 
 this.toggleNavbar = this.toggleNavbar.bind(this);
 this.state = {
 collapsed: true
 };
 }
 
 toggleNavbar () {
 this.setState({
 collapsed: !this.state.collapsed
 });
 }
 
 render () {
 return (
 <header>
 <Navbar className="navbar-expand-sm navbar-toggleable-sm ng-white border-bottom box-shadow mb-3" light>
 <Container>
 <NavbarBrand tag={Link} to="/">FastCubeReact</NavbarBrand>
 <NavbarToggler onClick={this.toggleNavbar} className="mr-2" />
 <Collapse className="d-sm-inline-flex flex-sm-row-reverse" isOpen={!this.state.collapsed} navbar>
 <ul className="navbar-nav flex-grow">
 <NavItem>
 <NavLink tag={Link} className="text-dark" to="/">Home</NavLink>
 </NavItem>
 <NavItem>
 <NavLink tag={Link} className="text-dark" to="/counter">Counter</NavLink>
 </NavItem>
 <NavItem>
 <NavLink tag={Link} className="text-dark" to="/fetch-data">Fetch data</NavLink>
 </NavItem>
 <NavItem>
 <NavLink tag={Link} className="text-dark" to="/cube">Cube</NavLink>
 </NavItem>
 </ul>
 </Collapse>
 </Container>
 </Navbar>
 </header>
 );
 }
}
 

The application is ready. Let's run it:

The web application displays the cube

Thus, you can display your web cube using FastCube.NET in a React SPA application.

ürün hakkında satın al
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastCube ASP.NET Core React SPA

Yorum ekle
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Satın al
  • İndir
  • Dökümantasyon
  • Geribildirimler
  • Ürünlerimizi nasıl kaldırabilirsiniz
  • SSS
  • Başlangıç için Video
  • Forum
  • Support SLA
  • Articles
  • Haberlerimiz
  • Basında Biz
  • Partnerler
  • Extended licensing
  • Bize Ulaşın

© 1998-2023 by Fast Reports Inc.

  • Gizlilik Politikası

Trustpilot