Search results

Getting Started with ASP.NET Core

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to include a license key in your projects. Refer to this link to know about registering Syncfusion license key in your ASP.NET Core application to use our components.

Prerequisites

To get started with the ASP.NET Core application, ensure that the following software are installed on the machine.

  • Visual Studio 2017
  • DotNet Core 2.0

Setup ASP.NET Core application with Essential JS 2 for ASP.NET Core

The following steps are used to create ASP.NET Core Application.

Step 1: Create ASP.NET Core Web Application with default template project in Visual Studio 2017.

Create Project Template

Step 2: Once your project created, add the Syncfusion EJ2 package into your application by using the NuGet Package Manager.

Open the NuGet package manager.

Solution Explorer

Install the Syncfusion.EJ2 package to the application

NuGet Demo

After Installation, this will be included in the project. You can refer it from the Project Assembly Reference.

Install the NewtonSoft.JSON as dependency since Syncfusion.EJ2 dependent to the NewtonSoft.JSON package.

Step 3: Open the Views/_ViewImports.cshtml to import Syncfusion.EJ2 package.

@addTagHelper *, Syncfusion.EJ2

Step 4: Add client-side resource through CDN or local package in the layout page Views/Shared/_Layout.cshtml.

<head>
@* Syncfusion Essential JS 2 Styles *@
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/material.css" />

@* Syncfusion Essential JS 2 Scripts *@
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>
</head>

Step 5: Adding Script Manager in the layout page Views/Shared/_Layout.cshtml.

<body>
    @RenderBody()
    @RenderSection("Scripts", required: false)
<ejs-scripts></ejs-scripts>
</body>

Step 6: Add the following code to your Index.cshtml view page which is present under Views/Home folder, to initialize the TreeGrid.

tagHelper
tree-grid.cs
<ejs-treegrid id="TreeGrid" dataSource=@ViewBag.DataSource height="380" childMapping="Children" treeColumnIndex="1" >
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="95"></e-treegrid-column>
             <e-treegrid-column field="TaskName" headerText="Task Name" width="220"></e-treegrid-column>
             <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" format="yMd" type="date" width="115"></e-treegrid-column>
             <e-treegrid-column field="EndDate" headerText=" End Date" textAlign="Right" format="yMd" type="date" width="115"></e-treegrid-column>
             <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="100"></e-treegrid-column>
             <e-treegrid-column field="Progress" headerText="Progress" textAlign="Right" width="105"></e-treegrid-column>
             <e-treegrid-column field="Priority" headerText="Priority" width="100"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
public IActionResult Index()
{
    var Order = TreeData.GetDefaultData();
    ViewBag.DataSource = Order;
    return View();
}

In the above code example, the hierarchical data binding is represented in which the ChilMapping property denotes the hierarchy relationship; whereas in self-referencing data binding IdMapping and ParentIdMapping denotes the hierarchy relationship.

Enable paging

The paging feature enables users to view the treegrid record in a paged view. It can be enabled by setting the AllowPaging property to true. The pager can be customized using the PageSettings property.

In root-level paging mode, paging is based on the root-level rows only, i.e., it ignores the child row count and it can be enabled by using the PageSettings.PageSizeMode property.

tagHelper
page.cs
<ejs-treegrid id="TreeGrid" dataSource="ViewBag.DataSource" allowPaging="true" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-pagesettings pageSizes="true" pageSize="10" pageCount="4"></e-treegrid-pagesettings>
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="95"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="220"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" format="yMd" type="date" width="115"></e-treegrid-column>
        <e-treegrid-column field="EndDate" headerText=" End Date" textAlign="Right" format="yMd" type="date" width="115"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="100"></e-treegrid-column>
        <e-treegrid-column field="Progress" headerText="Progress" textAlign="Right" width="105"></e-treegrid-column>
        <e-treegrid-column field="Priority" headerText="Priority" width="100"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
public IActionResult Index()
{
    var Order = TreeData.GetDefaultData();
    ViewBag.DataSource = Order;
    return View();
}

Enable sorting

The sorting feature enables you to order the records. It can be enabled by setting the AllowSorting property to true. Sorting feature can be customized using the SortSettings property.

tagHelper
sorting.cs
<ejs-treegrid id="TreeGrid" dataSource="ViewBag.DataSource" allowSorting="true" allowPaging="true" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-columns>
        <e-treegrid-column field="Name" headerText="Order Name" width="170"></e-treegrid-column>
        <e-treegrid-column field="ShipmentCategory" headerText="Category" width="150"></e-treegrid-column>
        <e-treegrid-column field="OrderDate" headerText="Order Date" textAlign="Right" format="yMd" type="date" width="130"></e-treegrid-column>
        <e-treegrid-column field="Units" headerText="Units" textAlign="Right" width="120"></e-treegrid-column>
        <e-treegrid-column field="UnitPrice" headerText="Unit Price" textAlign="Right" width="130"></e-treegrid-column>
        <e-treegrid-column field="Price" headerText="Price" textAlign="Right" format="c2" width="120"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
public IActionResult Index()
{
    var Order = TreeData.GetShipmentData();
    ViewBag.DataSource = Order;
    return View();
}

Enable filtering

The filtering feature enables you to view the reduced amount of records based on the filter criteria. It can be enabled by setting the AllowFiltering property to true. Filtering feature can be customized using the FilterSettings property.

By default, filtered records are shown along with its parent records. This behavior can be changed by using the FilterSettings-HierarchyMode property.

tagHelper
filtering.cs
<ejs-treegrid id="TreeGrid" dataSource="ViewBag.DataSource" allowFiltering="true" allowPaging="true" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-filtersettings type="FilterBar" hierarchyMode="Parent" mode="Immediate"></e-treegrid-filtersettings>
    <e-treegrid-pagesettings pageSize="10"></e-treegrid-pagesettings>
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="70"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="200"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" format="yMd" type="date" width="100"></e-treegrid-column>
        <e-treegrid-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
public IActionResult Index()
{
    var Order = TreeData.GetDefaultData();
    ViewBag.DataSource = Order;
    return View();
}

Output be like the below.

TreeGrid Sample Output