Blazor ComboBox는 사용자가 제공된 목록에서 다양한 미리 정의된 옵션을 쉽게 선택, 필터링 및 그룹화할 수 있는 가벼운 편집기입니다. 이 구성 요소는 또한 Blazor ComboBox 키보드 탐색, 항목, 헤더 및 푸터가 표시되는 방식을 사용자 정의하는 템플릿에 대한 옵션을 지원합니다.
Ignite UI for Blazor ComboBox 구성 요소는 사용자가 선택할 수 있는 옵션 목록을 제공합니다. 모든 옵션을 가상화된 항목 목록에 표시하므로 ComboBox는 동시에 수천 개의 레코드를 표시할 수 있으며, 여기서 하나 이상의 옵션을 선택할 수 있습니다. 또한 이 구성 요소는 대소문자 구분 필터링, 그룹화, 복잡한 데이터 바인딩 등을 제공합니다.
Blazor ComboBox Example
EXAMPLE
MODULES
DATA
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// required for registering IgniteUIBlazorusing IgniteUI.Blazor.Controls;
namespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Infragistics Blazor
builder.Services.AddIgniteUIBlazor(typeof(IgbComboModule));
await builder.Build().RunAsync();
}
}
}cs
using System;
using System.Collections;
using System.Collections.Generic;
namespaceInfragistics.Samples
{
publicclassCity {
publicstring Id { get; set; }
publicstring Name { get; set; }
publicstring Country { get; set; }
}
publicclassSampleData {
publicstatic List<City> Cities = GetCities();
publicstatic List<City> GetCities() {
var data = new List<City> {
new City {
Id = "UK01",
Name = "London",
Country = "United Kingdom",
},
new City {
Id = "UK02",
Name = "Manchester",
Country = "United Kingdom",
},
new City {
Id = "UK03",
Name = "Birmingham",
Country = "United Kingdom",
},
new City {
Id = "UK04",
Name = "Glasgow",
Country = "United Kingdom",
},
new City {
Id = "UK05",
Name = "Liverpool",
Country = "United Kingdom",
},
new City {
Id = "US01",
Name = "New York",
Country = "United States of America",
},
new City {
Id = "US02",
Name = "Miami",
Country = "United States of America",
},
new City {
Id = "US03",
Name = "Philadelphia",
Country = "United States of America",
},
new City {
Id = "US04",
Name = "Chicago",
Country = "United States of America",
},
new City {
Id = "US05",
Name = "Springfield",
Country = "United States of America",
},
new City {
Id = "US06",
Name = "Los Angeles",
Country = "United States of America",
},
new City {
Id = "US07",
Name = "Houston",
Country = "United States of America",
},
new City {
Id = "US08",
Name = "Phoenix",
Country = "United States of America",
},
new City {
Id = "US09",
Name = "San Diego",
Country = "United States of America",
},
new City {
Id = "US10",
Name = "Dallas",
Country = "United States of America",
},
new City {
Id = "BG01",
Name = "Sofia",
Country = "Bulgaria",
},
new City {
Id = "BG02",
Name = "Plovdiv",
Country = "Bulgaria",
},
new City {
Id = "BG03",
Name = "Varna",
Country = "Bulgaria",
},
new City {
Id = "BG04",
Name = "Burgas",
Country = "Bulgaria",
},
new City {
Id = "IT01",
Name = "Rome",
Country = "Italy",
},
new City {
Id = "IT02",
Name = "Milan",
Country = "Italy",
},
new City {
Id = "IT03",
Name = "Naples",
Country = "Italy",
},
new City {
Id = "IT04",
Name = "Turin",
Country = "Italy",
},
new City {
Id = "IT05",
Name = "Palermo",
Country = "Italy",
},
new City {
Id = "IT06",
Name = "Florence",
Country = "Italy",
},
};
return data;
}
}
}cs
// in Program.cs file
builder.Services.AddIgniteUIBlazor(typeof(IgbComboModule));
razor
IgbCombo 구성 요소에 스타일을 적용하려면 추가 CSS 파일을 연결해야 합니다. 다음은 Blazor Web Assembly 프로젝트의 wwwroot/index.html 파일이나 Blazor Server 프로젝트의 Pages/_Host.cshtml 파일에 배치해야 합니다.
The IgbCombo component doesn't work with the standard <form> element. Use Form instead.
그런 다음 옵션 목록을 작성하는 데 사용되는 콤보 데이터 소스에 개체 배열을 바인딩합니다.
<IgbComboId="basic-combo"DisplayKey="name"ValueKey="id"Data="Data" />@code {privateclassCity {
publicstring Id { get; set; }
publicstring Name { get; set; }
publicstring Country { get; set; }
}
private List<City> Data = new List<City> {
new City {
Id = "UK01",
Name = "London",
Country = "United Kingdom",
},
new City {
Id = "BG01",
Name = "Sofia",
Country = "Bulgaria",
},
new City {
Id = "US01",
Name = "New York",
Country = "United States",
},
};
}razor
Data value and display properties
콤보가 복잡한 데이터(예: 개체) 목록에 바인딩된 경우 컨트롤이 항목 선택을 처리하는 데 사용할 속성을 지정해야 합니다. 구성 요소는 다음 속성을 노출합니다.
ValueKey-선택 과목,필수의복잡한 데이터 객체의 경우- 선택하는 데 사용할 데이터 소스의 필드를 결정합니다. 만약에 ValueKey 생략되면 선택 API는 개체 참조를 사용하여 항목을 선택합니다.
DisplayKey-선택 과목,추천복잡한 데이터 객체의 경우- 표시 값으로 사용되는 데이터 소스의 필드를 결정합니다. 값이 지정되지 않은 경우 DisplayKey, 콤보는 지정된 ValueKey (만약에 어떠한). 우리의 경우 콤보가 다음을 표시하기를 원합니다. name 각 도시의 id 항목 선택을 위한 필드와 각 항목의 기본 값으로 사용됩니다. 따라서 우리는 이러한 속성을 콤보의 속성에 제공합니다. ValueKey 그리고 DisplayKey 각기.
When the data source consists of primitive types (e.g. strings, numbers, etc.), do not specify a ValueKey and/or DisplayKey.
Setting Value
ComboBox 구성 요소는 값이라고도 하는 속성 외에도 Value getter 및 setter를 노출합니다. value 속성을 사용하여 구성 요소 초기화 시 선택한 항목을 설정할 수 있습니다.
값(즉, 현재 선택된 항목의 목록)을 읽거나 값을 업데이트하려면 각각 value getter 및 setter를 사용하십시오. 값 getter는 ValueKey로 표시되는 선택된 모든 항목의 목록을 반환합니다. 마찬가지로, 값 설정기를 사용하여 선택한 항목 목록을 업데이트하려면 해당 ValueKey로 항목 목록을 제공해야 합니다.
본보기:
Selection API
콤보 구성 요소는 현재 선택한 항목을 변경할 수 있는 API를 노출합니다.
사용자 상호 작용을 통해 옵션 목록에서 항목을 선택하는 것 외에도 프로그래밍 방식으로 항목을 선택할 수 있습니다. 이는 select 및 deselect 메소드를 통해 수행됩니다. 항목 배열을 두 메서드 모두에 전달할 수 있습니다. 인수 없이 메서드를 호출하면 호출되는 메서드에 따라 모든 항목이 선택/선택 해제됩니다. 콤보 구성 요소에 대해 ValueKey 지정한 경우 선택/선택 취소하려는 항목의 값 키를 전달해야 합니다.
ValueKey 속성이 생략된 경우 개체 참조로 선택/선택 취소하려는 항목을 나열해야 합니다.
EXAMPLE
MODULES
DATA
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// required for registering IgniteUIBlazorusing IgniteUI.Blazor.Controls;
namespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Infragistics Blazor
builder.Services.AddIgniteUIBlazor(typeof(IgbComboModule));
builder.Services.AddIgniteUIBlazor(typeof(IgbButtonModule));
await builder.Build().RunAsync();
}
}
}cs
using System;
using System.Collections;
using System.Collections.Generic;
namespaceInfragistics.Samples
{
publicclassCity {
publicstring Id { get; set; }
publicstring Name { get; set; }
publicstring Country { get; set; }
}
publicclassSampleData {
publicstatic List<City> Cities = GetCities();
publicstatic List<City> GetCities() {
var data = new List<City> {
new City {
Id = "UK01",
Name = "London",
Country = "United Kingdom",
},
new City {
Id = "UK02",
Name = "Manchester",
Country = "United Kingdom",
},
new City {
Id = "UK03",
Name = "Birmingham",
Country = "United Kingdom",
},
new City {
Id = "UK04",
Name = "Glasgow",
Country = "United Kingdom",
},
new City {
Id = "UK05",
Name = "Liverpool",
Country = "United Kingdom",
},
new City {
Id = "US01",
Name = "New York",
Country = "United States of America",
},
new City {
Id = "US02",
Name = "Miami",
Country = "United States of America",
},
new City {
Id = "US03",
Name = "Philadelphia",
Country = "United States of America",
},
new City {
Id = "US04",
Name = "Chicago",
Country = "United States of America",
},
new City {
Id = "US05",
Name = "Springfield",
Country = "United States of America",
},
new City {
Id = "US06",
Name = "Los Angeles",
Country = "United States of America",
},
new City {
Id = "US07",
Name = "Houston",
Country = "United States of America",
},
new City {
Id = "US08",
Name = "Phoenix",
Country = "United States of America",
},
new City {
Id = "US09",
Name = "San Diego",
Country = "United States of America",
},
new City {
Id = "US10",
Name = "Dallas",
Country = "United States of America",
},
new City {
Id = "BG01",
Name = "Sofia",
Country = "Bulgaria",
},
new City {
Id = "BG02",
Name = "Plovdiv",
Country = "Bulgaria",
},
new City {
Id = "BG03",
Name = "Varna",
Country = "Bulgaria",
},
new City {
Id = "BG04",
Name = "Burgas",
Country = "Bulgaria",
},
new City {
Id = "IT01",
Name = "Rome",
Country = "Italy",
},
new City {
Id = "IT02",
Name = "Milan",
Country = "Italy",
},
new City {
Id = "IT03",
Name = "Naples",
Country = "Italy",
},
new City {
Id = "IT04",
Name = "Turin",
Country = "Italy",
},
new City {
Id = "IT05",
Name = "Palermo",
Country = "Italy",
},
new City {
Id = "IT06",
Name = "Florence",
Country = "Italy",
},
};
return data;
}
}
}cs
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// required for registering IgniteUIBlazorusing IgniteUI.Blazor.Controls;
namespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Infragistics Blazor
builder.Services.AddIgniteUIBlazor(typeof(IgbComboModule));
builder.Services.AddIgniteUIBlazor(typeof(IgbIconModule));
await builder.Build().RunAsync();
}
}
}cs
using System;
using System.Collections;
using System.Collections.Generic;
namespaceInfragistics.Samples
{
publicclassCity {
publicstring Id { get; set; }
publicstring Name { get; set; }
publicstring Country { get; set; }
}
publicclassSampleData {
publicstatic List<City> Cities = GetCities();
publicstatic List<City> GetCities() {
var data = new List<City> {
new City {
Id = "UK01",
Name = "London",
Country = "United Kingdom",
},
new City {
Id = "UK02",
Name = "Manchester",
Country = "United Kingdom",
},
new City {
Id = "UK03",
Name = "Birmingham",
Country = "United Kingdom",
},
new City {
Id = "UK04",
Name = "Glasgow",
Country = "United Kingdom",
},
new City {
Id = "UK05",
Name = "Liverpool",
Country = "United Kingdom",
},
new City {
Id = "US01",
Name = "New York",
Country = "United States of America",
},
new City {
Id = "US02",
Name = "Miami",
Country = "United States of America",
},
new City {
Id = "US03",
Name = "Philadelphia",
Country = "United States of America",
},
new City {
Id = "US04",
Name = "Chicago",
Country = "United States of America",
},
new City {
Id = "US05",
Name = "Springfield",
Country = "United States of America",
},
new City {
Id = "US06",
Name = "Los Angeles",
Country = "United States of America",
},
new City {
Id = "US07",
Name = "Houston",
Country = "United States of America",
},
new City {
Id = "US08",
Name = "Phoenix",
Country = "United States of America",
},
new City {
Id = "US09",
Name = "San Diego",
Country = "United States of America",
},
new City {
Id = "US10",
Name = "Dallas",
Country = "United States of America",
},
new City {
Id = "BG01",
Name = "Sofia",
Country = "Bulgaria",
},
new City {
Id = "BG02",
Name = "Plovdiv",
Country = "Bulgaria",
},
new City {
Id = "BG03",
Name = "Varna",
Country = "Bulgaria",
},
new City {
Id = "BG04",
Name = "Burgas",
Country = "Bulgaria",
},
new City {
Id = "IT01",
Name = "Rome",
Country = "Italy",
},
new City {
Id = "IT02",
Name = "Milan",
Country = "Italy",
},
new City {
Id = "IT03",
Name = "Naples",
Country = "Italy",
},
new City {
Id = "IT04",
Name = "Turin",
Country = "Italy",
},
new City {
Id = "IT05",
Name = "Palermo",
Country = "Italy",
},
new City {
Id = "IT06",
Name = "Florence",
Country = "Italy",
},
};
return data;
}
}
}cs