Web Components コンボボックスの機能
Ignite UI for Web Components コンボボックス コンポーネントは、フィルタリングやグループ化などのいくつかの機能を公開しています。
コンボボックス機能の例
以下のデモは、ランタイムで有効または無効にできるいくつかの ComboBox
機能を示しています。
import { defineComponents, IgcComboComponent, IgcSwitchComponent } from "igniteui-webcomponents" ;
import "igniteui-webcomponents/themes/light/bootstrap.css" ;
import "./index.css" ;
defineComponents(IgcComboComponent, IgcSwitchComponent);
interface City {
id : string ;
name: string ;
country: string ;
}
const cities: City[] = [
{ name : "London" , id : "UK01" , country : "UK" },
{ name : "Manchester" , id : "UK02" , country : "UK" },
{ name : "Birmingham" , id : "UK03" , country : "UK" },
{ name : "Glasgow" , id : "UK04" , country : "UK" },
{ name : "Liverpool" , id : "UK05" , country : "UK" },
{ name : "New York" , id : "US01" , country : "USA" },
{ name : "Miami" , id : "US02" , country : "USA" },
{ name : "Philadelphia" , id : "US03" , country : "USA" },
{ name : "Chicago" , id : "US04" , country : "USA" },
{ name : "Springfield" , id : "US05" , country : "USA" },
{ name : "Los Angeles" , id : "US06" , country : "USA" },
{ name : "Houston" , id : "US07" , country : "USA" },
{ name : "Phoenix" , id : "US08" , country : "USA" },
{ name : "San Diego" , id : "US09" , country : "USA" },
{ name : "Dallas" , id : "US010" , country : "USA" },
{ name : "Sofia" , id : "BG01" , country : "Bulgaria" },
{ name : "Plovdiv" , id : "BG02" , country : "Bulgaria" },
{ name : "Varna" , id : "BG03" , country : "Bulgaria" },
{ name : "Burgas" , id : "BG04" , country : "Bulgaria" },
{ name : "Rome" , id : "IT01" , country : "Italy" },
{ name : "Milan" , id : "IT02" , country : "Italy" },
{ name : "Naples" , id : "IT03" , country : "Italy" },
{ name : "Turin" , id : "IT04" , country : "Italy" },
{ name : "Palermo" , id : "IT05" , country : "Italy" },
{ name : "Florence" , id : "IT06" , country : "Italy" }
];
export class ComboFeatures {
private combo: IgcComboComponent<City>;
constructor ( ) {
this .combo = document .getElementById("combo" ) as IgcComboComponent<City>;
this .combo.data = cities;
let switchIcon = document .getElementById("caseSensitive" ) as IgcSwitchComponent;
let switchFilter = document .getElementById("filtering" ) as IgcSwitchComponent;
let switchGroup = document .getElementById("grouping" ) as IgcSwitchComponent;
let switchDisable = document .getElementById("disabled" ) as IgcSwitchComponent;
switchIcon.addEventListener("igcChange" , () => {
this .combo.caseSensitiveIcon = switchIcon.checked;
});
switchFilter.addEventListener("igcChange" , () => {
this .combo.disableFiltering = switchIcon.disabled = switchFilter.checked;
});
switchGroup.addEventListener("igcChange" , () => {
this .combo.groupKey = switchGroup.checked ? "country" : undefined ;
});
switchDisable.addEventListener("igcChange" , () => {
this .combo.disabled = switchDisable.checked;
});
}
}
new ComboFeatures();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Combo Features</title >
<meta charset ="UTF-8" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" type ="text/css" />
<link href ="https://static.infragistics.com/xplatform/css/samples/custom-legend.css" rel ="stylesheet" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample center" >
<igc-combo
id ="combo"
value-key ="id"
display-key ="name"
label ="Cities"
placeholder ="Pick a city"
placeholder-search ="Search for a city"
>
</igc-combo >
<div class ="options" >
<igc-switch id ="filtering" > Disable Filtering</igc-switch >
<igc-switch id ="caseSensitive" > Show Case-sensitive Icon</igc-switch >
<igc-switch id ="grouping" > Enable Grouping</igc-switch >
<igc-switch id ="disabled" > Disable Combo</igc-switch >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
.options {
display : flex;
flex-direction : column;
margin-top : 12px ;
gap: 8px ;
}
css コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
このサンプルでは、IgcSwitchComponent
コンポーネントを使用するため、コンボと一緒に登録する必要があります。
import { defineComponents, IgcComboComponent, IgcSwitchComponent } from 'igniteui-webcomponents' ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
defineComponents(IgcComboComponent, IgcSwitchComponent);
ts
let combo = document .getElementById('combo' ) as IgcComboComponent<City>;
let switchIcon = document .getElementById('caseSensitive' ) as IgcSwitchComponent;
let switchFilter = document .getElementById('filtering' ) as IgcSwitchComponent;
let switchDisable = document .getElementById('disabled' ) as IgcSwitchComponent;
switchIcon.addEventListener("igcChange" , () => {
combo.caseSensitiveIcon = switchIcon.checked;
});
switchFilter.addEventListener("igcChange" , () => {
combo.disableFiltering = switchIcon.disabled = switchFilter.checked;
});
switchDisable.addEventListener("igcChange" , () => {
combo.disabled = switchDisable.checked;
});
ts
グループ化は、groupKey
プロパティを対応するデータ ソース フィールドに設定することで有効/無効になることに注意してください。
let switchGroup = document .getElementById('grouping' ) as IgcSwitchComponent;
switchGroup.addEventListener("igcChange" , () => {
this .combo.groupKey = switchGroup.checked ? "country" : undefined ;
});
ts
機能
フィルタリング
コンボボックスのフィルタリングがデフォルトで有効になります。無効にするには、disableFiltering
プロパティを設定します。
フィルタリング オプションは、検索の大文字と小文字の区別を有効にすることでさらに拡張できます。caseSensitiveIcon
プロパティを使用して大文字と小文字を区別するアイコンをオンにすると、エンド ユーザーは大文字と小文字の区別を制御できます。
<igc-combo disable-filtering case-sensitive-icon > </igc-combo >
html
フィルタリング オプション
Ignite UI for Web Components ComboBox
コンポーネントは、FilterKey
オプションと CaseSensitive
オプションの両方の構成を渡すことができるフィルター プロパティをもう 1 つ公開しています。FilterKey
は、オプションのリストをフィルタリングするためにどのデータ ソース フィールドを使用する必要があるかを示します。CaseSensitive
オプションは、フィルタリングで大文字と小文字を区別するかどうかを示します。
次のコード スニペットは、名前ではなく国でデータ ソースから都市をフィルター処理する方法を示しています。また、デフォルトで大文字と小文字を区別するフィルタリングを行います。
const options = {
filterKey : 'country' ,
caseSensitive : true
};
combo.filteringOptions = options;
ts
グループ化
groupKey
オプションを定義すると、キーに基づいて項目をグループ化します。
<igc-combo group-key ="region" > </igc-combo >
html
groupKey プロパティは、データ ソースが複雑なオブジェクトで構成されている場合にのみ有効です。
ソートの方向
コンボボックス コンポーネントは、グループを昇順または降順でソートするかどうかを設定するオプションも公開します。デフォルトでは、ソート順序は、昇順に設定されています。
<igc-combo group-sorting ="desc" > </igc-combo >
html
ラベル
IgcComboComponent
ラベルは、label
プロパティを使用して簡単に設定できます。
<igc-combo label ="Cities" > </igc-combo >
html
プレースホルダー
コンボボックス コンポーネント入力とドロップダウン メニュー内に配置された検索入力の両方に、プレースホルダー テキストを指定できます。
<igc-combo placeholder ="Pick a city" placeholder-search ="Search for a city" > </igc-combo >
html
オートフォーカス
コンボボックスをページの読み込みに自動的にフォーカスさせたい場合は、次のコードを使用できます。
<igc-combo autofocus > </igc-combo >
html
検索入力のフォーカス
コンボボックスの検索入力はデフォルトでフォーカスされています。この機能を無効にしてフォーカスをオプションのリストに移動するには、以下に示すように autofocusList
プロパティを使用します。
<igc-combo autofocus-list > </igc-combo >
html
必須
required プロパティを設定することで、コンボボックスを必須としてマークできます。
<igc-combo required > </igc-combo >
html
コンボボックスを無効にする
disabled
プロパティを使用してコンボボックスを無効にできます。
<igc-combo disabled > </igc-combo >
html
API リファレンス
その他のリソース