ASP.NET Core Blazor [Preview]
Search results

Getting Started with Essential JS 2 for ASP.NET Core Razor Components in Visual Studio 2019

This article provides a step-by-step introduction to configure Essential JS 2 setup, build and publish a simple .NET Core Razor Components web application using the Visual Studio 2019.

Prerequisites

The official prerequisites to create and run an ASP.NET Core Razor Components on Windows environment are described in the .NET Core Razor components documentation website.

Create a Pivot Grid Component in Blazor application from VS 2019

Step 1: Choose File > New > Project… in the Visual Studio menu bar.

new project in aspnetcore razor

Step 2: Make sure .NET Core and ASP.NET Core 3.0 are selected at the top.

select framework

Step 3: Choose the Blazor template and change the application name, and then click OK.

Importing Essential JS 2 Razor components in the application

Step 1: Now, add the Syncfusion.EJ2.AspNet.Core.RazorComponents NuGet package to the new application by using the NuGet Package Manager. Right-click the project and select Manage NuGet Packages.

nuget explorer

Step 2: Search the Syncfusion.EJ2.AspNet.Core.RazorComponents keyword in the Browse tab and install Syncfusion.EJ2.AspNet.Core.RazorComponents NuGet package in the application.

select nuget

Step 3: The Essential JS 2 package will be included in the project, after the installation process is completed.

Step 4: Open ~/_Imports.cshtml file and import the Syncfusion.EJ2.RazorComponents.

    @using Syncfusion.EJ2.RazorComponents
    @using Syncfusion.EJ2.RazorComponents.PivotView

Step 5: Add the client-side resources through CDN or local npm package in the <head> element of the ~/wwwroot/index.html page.

import cdn

Step 6: Now, add the Syncfusion Essential JS 2 components in any web page (cshtml) in the Pages folder. For example, the Pivot Grid component is added in the ~/Pages/Index.cshtml page.

     <EjsPivotView ID="pivotgrid" ref="pivotGrid" Width="100%" Height="300" DataSource="@PivotDataSource" ShowFieldList=true></EjsPivotView>

    @functions{
        EjsPivotView pivotView;

        static PivotViewData pivotData = new PivotViewData();

        static List<object> pivotRows { get; set; } = new List<object>
        {
        new { name = "Country" },
        new { name = "Products" }
        };

        static List<object> pivotColumns { get; set; } = new List<object>
        {
        new { name = "Year" },
        new { name = "Quarter" }
        };

        static List<object> pivotValues { get; set; } = new List<object>
        {
        new { name = "Sold", caption = "Units Sold" },
        new { name = "Amount", caption = "Sold Amount" }
        };

        static List<object> pivotFormats { get; set; } = new List<object>
        {
        new { name = "Amount", format = "C0", maximumSignificantDigits = 10, minimumSignificantDigits = 1, useGrouping = true }
        };
        [Parameter]
        private object PivotDataSource { get; set; } = new
        {
            data = pivotData.GetDefaultData(),
            expandAll = false,
            enableSorting = true,
            rows = pivotRows,
            columns = pivotColumns,
            values = pivotValues,
            formatSettings = pivotFormats
        };
    }

Step 7: Run the application. The Essential JS 2 Pivot Grid component will render in the web browser.

output