Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Mvc;
using filter_core.Models;
using Syncfusion.EJ2.Base;
using System.Text.Json;

namespace TestSample.Controllers
{
Expand All @@ -21,27 +22,30 @@ public IActionResult Index()
ViewBag.DataSource = Order;

return View();
}
}

public IActionResult StateDataSource([FromBody]ExtendedDataManager dm)
{
public IActionResult StateDataSource([FromBody] ExtendedDataManager dm)
{
var states = States.getStates();

var state = States.getStates();

var Data = state.ToList();
int count = state.Count();
int countryId = 0;

if (dm.Where != null && dm.Where.Count > 0)
{
var jsonValue = (JsonElement)dm.Where[0].value;

List<States> iterateState= new List<States>();
foreach (States st in state) {
if (st.countryId == (Int64)dm.Where[0].value) {
iterateState.Add(st);
}
}
return dm.RequiresCounts ? Json(new { result = Data.Skip(dm.Skip).Take(dm.Take), count = count }) : Json(iterateState.ToList());
if (jsonValue.ValueKind == JsonValueKind.Number)
{
countryId = jsonValue.GetInt32(); // or GetInt64()
}
}

var filteredStates = states
.Where(st => st.countryId == countryId)
.ToList();

return Json(filteredStates);
}
public IActionResult CountryDataSource([FromBody]ExtendedDataManager dm)
{

Expand Down
27 changes: 13 additions & 14 deletions Cascading-dropdown-remote-data/filter_core/filter_core/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace filter_core
{
Expand All @@ -18,33 +15,35 @@ public Startup(IConfiguration configuration)

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
// Register services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
// Configure HTTP request pipeline
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseStaticFiles();

app.UseMvc(routes =>
app.UseRouting();

app.UseEndpoints(endpoints =>
{
routes.MapRoute(
endpoints.MapControllerRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - filter_core</title>
@* Syncfusion Essential JS 2 Styles *@
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/material.css" />
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/33.1.44/material3.css" />

@* Syncfusion Essential JS 2 Scripts *@
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="17.3.0.14" />
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="33.1.44" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
</ItemGroup>

</Project>
</Project>
57 changes: 49 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
# ASP.MET CORE DataGrid - Cascading Dropdown Remote Data Editing in Data Binding
# ASP.NET Core DataGrid Cascading Dropdown Editing with Remote Data

This sample explains about how to achieve the cascading dropdown with remote data-binding in the ASP.NET Core DataGrid inline editing.
## Repository Description

This repository demonstrates how to implement cascading dropdown editors with remote data binding inside an ASP.NET Core DataGrid during inline editing scenarios.

## Project Overview

This sample project shows how to configure the Syncfusion ASP.NET Core DataGrid to support cascading DropDownList components when editing grid rows. The primary use case is handling dependent fields such as Country and State, where the available options in one dropdown depend on the selected value of another.

The grid is configured with inline CRUD operations and retrieves its dropdown data from remote endpoints using the `UrlAdaptor`. JavaScript editor lifecycle methods (`create`, `read`, `write`, and `destroy`) are used to fully control the behavior of each dropdown editor.

## Key Features

- Inline editing with Add, Edit, Delete, Update, and Cancel actions
- Cascading dropdown editors inside grid columns
- Remote data loading using DataManager and UrlAdaptor
- Dynamic filtering of dependent dropdown values
- Clean separation of grid configuration and editor logic

## Technologies Used

- ASP.NET Core MVC
- Syncfusion EJ2 ASP.NET Core DataGrid
- JavaScript (EJ2 DropDownList components)
- Remote data binding using Web API endpoints

## Prerequisites

* Visual Studio 2022
- Visual Studio 2022
- .NET SDK compatible with ASP.NET Core
- Syncfusion EJ2 ASP.NET Core packages

## Functionality

When a country is selected in the `ShipCountry` column, the `ShipCity` dropdown is enabled and filtered dynamically using a query based on the selected country ID. The state dropdown remains disabled until a valid country selection is made, ensuring proper cascading behavior.

## Running the Application

1. Clone or download the repository to your local machine.
```
git clone <repo_link>
```
2. Open the solution file in Visual Studio 2022.
3. Restore NuGet packages by rebuilding the solution.
4. Run the project and navigate to the home page to view the grid.

## Usage
Use the toolbar buttons to add or edit a record. Select a country first, then choose the corresponding state from the filtered dropdown list.

## How to run the project
## Reference Documentation:

* Checkout this project to a location in your disk.
* Open the solution file using the Visual Studio 2022.
* Restore the NuGet packages by rebuilding the solution.
* Run the project.
- [Getting started with ASP.NET CORE Grid](https://ej2.syncfusion.com/aspnetcore/documentation/grid/getting-started-core)
- [Editing](https://ej2.syncfusion.com/aspnetcore/documentation/grid/editing/edit)
- [API Reference](https://help.syncfusion.com/cr/aspnetcore-js2/syncfusion.ej2.grids.grid.html)
Loading