Web Components ComboBox는 사용자가 제공된 목록에서 미리 정의된 다양한 옵션을 쉽게 선택, 필터링 및 그룹화할 수 있는 경량 편집기입니다. 이 구성 요소는 Web Components ComboBox 키보드 탐색 옵션, 항목, 머리글 및 바닥글이 표시되는 방식을 사용자 지정하는 템플릿도 지원합니다.
Ignite UI for Web Components ComboBox 구성 요소는 사용자가 선택할 수 있는 옵션 목록을 제공합니다. 모든 옵션을 가상화된 항목 목록에 표시하므로 ComboBox는 하나 이상의 옵션을 선택할 수 있는 수천 개의 레코드를 동시에 표시할 수 있습니다. 또한 이 구성 요소는 대소문자 구분 필터링, 그룹화, 복잡한 데이터 바인딩 등을 제공합니다.
<!DOCTYPE html><html><head><title>Combo Overview</title><metacharset="UTF-8" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /><linkhref="https://static.infragistics.com/xplatform/css/samples/custom-legend.css"rel="stylesheet"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-comboid='combo'value-key='id'display-key='name'value='["BG01"]'
></igc-combo></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
Getting Started with Web Components ComboBox
먼저 다음 명령을 실행하여 Ignite UI for Web Components 설치해야 합니다.
npm install igniteui-webcomponents
cmd
구성 요소를 사용하기 ComboBox 전에 추가 구성 요소 및 필요한 CSS와 함께 등록해야 합니다.
콤보가 복잡한 데이터(예: 개체) 목록에 바인딩된 경우 컨트롤이 항목 선택을 처리하는 데 사용할 속성을 지정해야 합니다. 구성 요소는 다음 속성을 노출합니다.
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로 항목 목록을 제공해야 합니다.
본보기:
const combo = document.getElementById('basic-combo') as IgcComboComponent<City>;
// Given the overview example from above this will return ['BG01']console.log(combo.value);
// Change the selected items to New York and London
combo.value = ['NY01', 'UK01'];
ts
Selection API
콤보 구성 요소는 현재 선택한 항목을 변경할 수 있는 API를 노출합니다.
사용자 상호 작용을 통해 옵션 목록에서 항목을 선택하는 것 외에도 프로그래밍 방식으로 항목을 선택할 수 있습니다. 이는 select 및 deselect 메소드를 통해 수행됩니다. 항목 배열을 두 메서드 모두에 전달할 수 있습니다. 인수 없이 메서드를 호출하면 호출되는 메서드에 따라 모든 항목이 선택/선택 취소됩니다. 콤보 구성 요소에 대해 valueKey 지정한 경우 선택/선택 취소하려는 항목의 값 키를 전달해야 합니다.
일부 항목 선택/선택 취소:
// Select/deselect items by their IDs as valueKey is set to 'id'
combo.select(['BG01', 'BG02', 'BG03', 'BG04']);
combo.deselect(['BG01', 'BG02', 'BG03', 'BG04']);
ts
모든 항목 선택/선택 취소:
// Select/deselect all items
combo.select();
combo.deselect();
ts
valueKey 속성이 생략된 경우 개체 참조로 선택/선택 취소하려는 항목을 나열해야 합니다.
// Select/deselect values by object references when no valueKey is provided
combo.select([cities[1], cities[5]]);
combo.deselect([cities[1], cities[5]]);
ts
<!DOCTYPE html><html><head><title>Combo Selection API</title><metacharset="UTF-8" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /><linkhref="https://static.infragistics.com/xplatform/css/samples/custom-legend.css"rel="stylesheet"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-comboid="combo"value-key="id"display-key="name"label="Cities"placeholder="Pick a city"placeholder-search="Search for a city"
></igc-combo><divclass="button-container"><igc-buttonid="select">Select UK Cities</igc-button><igc-buttonid="deselect">Deselect UK Favorites</igc-button><igc-buttonid="selectAll">Select All</igc-button><igc-buttonid="deselectAll">Deselect All</igc-button></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
<!DOCTYPE html><html><head><title>Combo Styling</title><metacharset="UTF-8" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /><linkhref="https://static.infragistics.com/xplatform/css/samples/custom-legend.css"rel="stylesheet"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-comboid="combo"value-key="id"display-key="name"group-key="country"label="Destinations"case-sensitive-icon
><spanslot="helper-text">Choose the desired place</span><igc-iconslot="prefix"name="place"collection="material"></igc-icon></igc-combo></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html