Skip to content

Added list box grouping sample #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
16 changes: 16 additions & 0 deletions Blazor Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Syncfusion.Blazor.DropDowns" Version="19.3.0.44" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
private int currentCount = 0;

private void IncrementCount()
{
currentCount++;
}
}
55 changes: 55 additions & 0 deletions Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@page "/fetchdata"
@inject HttpClient Http

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}

@code {
private WeatherForecast[] forecasts;

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public string Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
59 changes: 59 additions & 0 deletions Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@page "/"

<div class="listbox1">
<SfListBox TValue="string[]" TItem="ListBoxDataModel" DataSource="@ListBoxData" Scope="@scope"
AllowDragAndDrop="true">
<ListBoxFieldSettings Value="Id" Text="Vegetable" GroupBy="Category"></ListBoxFieldSettings>
</SfListBox>
</div>
<div class="listbox2">
<SfListBox TValue="string[]" TItem="ListBoxDataModel" DataSource="@ListBoxData1" Scope="@scope"
AllowDragAndDrop="true">
<ListBoxFieldSettings Value="Id" Text="Vegetable" GroupBy="Category"></ListBoxFieldSettings>
</SfListBox>
</div>

@code {
private readonly string scope = "combined-list";

public class ListBoxDataModel
{
public string Id { get; set; }
public string Vegetable { get; set; }
public string Category { get; set; }
}

List<ListBoxDataModel> ListBoxData = new List<ListBoxDataModel>()
{
new ListBoxDataModel() { Id = "item1", Vegetable = "Cabbage", Category = "Leafy and Salad" },
new ListBoxDataModel() { Id = "item2", Vegetable = "Chickpea", Category = "Beans" },
new ListBoxDataModel() { Id = "item3", Vegetable = "Garlic", Category = "Bulb and Stem" },
new ListBoxDataModel() { Id = "item4", Vegetable = "Green bean", Category = "Beans" },
new ListBoxDataModel() { Id = "item5", Vegetable = "Onion", Category = "Bulb and Stem" },
new ListBoxDataModel() { Id = "item6", Vegetable = "Pumpkins", Category = "Leafy and Salad" },

};
List<ListBoxDataModel> ListBoxData1 = new List<ListBoxDataModel>()
{
new ListBoxDataModel() { Id = "item1", Vegetable = "Spinach", Category = "Leafy and Salad" },
new ListBoxDataModel() { Id = "item2", Vegetable = "Horse gram", Category = "Beans" },
new ListBoxDataModel() { Id = "item3", Vegetable = "Nopal", Category = "Bulb and Stem" },
new ListBoxDataModel() { Id = "item4", Vegetable = "Soybeans", Category = "Beans" },
new ListBoxDataModel() { Id = "item5", Vegetable = "Cardoon", Category = "Bulb and Stem" },
new ListBoxDataModel() { Id = "item6", Vegetable = "Yarrow", Category = "Leafy and Salad" },

};

}

<style>
.listbox1 {
width: 48%;
float: left;
}

.listbox2 {
width: 48%;
float: right;
}
</style>
29 changes: 29 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Syncfusion.Blazor;

namespace Blazor_Sample
{
public class Program
{
public static async Task Main(string[] args)
{
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("NTI4NjA2QDMxMzkyZTMzMmUzMEJtOVJ1MXlUM3U4bTNzdGM1N3JnU1hKZXBNV01WNDUxYi9ERVhXNlJXVzQ9");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddSyncfusionBlazor();

await builder.Build().RunAsync();
}
}
}
29 changes: 29 additions & 0 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:24021",
"sslPort": 44335
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Blazor Sample": {
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# group-blazor-listbox-items
# How to Group the Blazor ListBox Items

A quick start Blazor project that shows how to group the Blazor ListBox items. This project also includes a code snippet to drag and drop the items between one or more list boxes.

Examples: https://blazor.syncfusion.com/demos/listbox/drag-and-drop

Documentation:

https://blazor.syncfusion.com/documentation/listbox/sorting-grouping

https://blazor.syncfusion.com/documentation/listbox/drag-and-drop


## Project pre-requisites
Make sure that you have the compatible versions of Visual Studio 2019 and .NET Core SDK latest version(3.1.2) in your machine before starting to work on this project.

## How to run this application?
To run this application, you need to first clone the group-blazor-listbox-items repository and then open it in Visual Studio 2019. Now, simply build and run your project to view the output.


15 changes: 15 additions & 0 deletions Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@inherits LayoutComponentBase

<div class="sidebar">
<NavMenu />
</div>

<div class="main">
<div class="top-row px-4">
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
</div>

<div class="content px-4">
@Body
</div>
</div>
37 changes: 37 additions & 0 deletions Shared/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="top-row pl-4 navbar navbar-dark">
<a class="navbar-brand" href="">Blazor Sample</a>
<button class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<ul class="nav flex-column">
<li class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</li>
</ul>
</div>

@code {
private bool collapseNavMenu = true;

private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
16 changes: 16 additions & 0 deletions Shared/SurveyPrompt.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="alert alert-secondary mt-4" role="alert">
<span class="oi oi-pencil mr-2" aria-hidden="true"></span>
<strong>@Title</strong>

<span class="text-nowrap">
Please take our
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2127996">brief survey</a>
</span>
and tell us what you think.
</div>

@code {
// Demonstrates how a parent component can supply parameters
[Parameter]
public string Title { get; set; }
}
11 changes: 11 additions & 0 deletions _Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using Blazor_Sample
@using Blazor_Sample.Shared
@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Data
Loading