Web Components Grid 検索フィルター
Web Components Grid の Ignite UI for Web Components 検索フィルター機能を使用すると、データのコレクション内の値を検索するプロセスが可能になります。この機能のセットアップが簡単になり、検索入力ボックス、ボタン、キーボード ナビゲーション、その他の便利な機能を使用して実装できるため、ユーザー エクスペリエンスがさらに向上します。ブラウザーにはネイティブなコンテンツ検索機能がありますが、ほとんどの場合で IgcGridComponent
は表示範囲外の行列を仮想化します。そのため、ネイティブ ブラウザー検索は DOM の一部でないため仮想化セルでデータを検索できません。IgcGridComponent
では、Web Components Material テーブル ベースのグリッドの拡張により、検索 API を使用した仮想コンテンツ の検索が可能です。
Web Components 検索の例
次の例は、すべての列と行を検索できる検索入力ボックスと、各列の特定のフィルタリング オプションを備えた IgcGridComponent
を表しています。
export class MarketRecord {
public constructor (init: Partial<MarketRecord> ) {
Object .assign(this , init);
}
public IndustryGroup: string ;
public IndustrySector: string ;
public SectorType: string ;
public KRD: number ;
public MarketNotion: number ;
public Date : string ;
}
export class MarketData extends Array <MarketRecord >
{
public constructor ( ) {
super ();
this .push(new MarketRecord(
{
Date : "new" ,
IndustryGroup : "Airlines" ,
IndustrySector : "Consumer" ,
KRD : 6E-05 ,
MarketNotion : 47338486.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 1.46433 ,
MarketNotion : 42605156.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 0.0 ,
MarketNotion : 41030865.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 6E-05 ,
MarketNotion : 30346443.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Retail" ,
IndustrySector : "Consumer, Cyclical" ,
KRD : 0.20296 ,
MarketNotion : 25111160.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Sovereign" ,
IndustrySector : "Government" ,
KRD : 0.05421 ,
MarketNotion : 23189929.0 ,
SectorType : "US GOVERNMENT"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.00031 ,
MarketNotion : 19365191.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 16235303.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : 0.00087 ,
MarketNotion : 11072448.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : -0.00063 ,
MarketNotion : 7550053.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : -1E-05 ,
MarketNotion : 6372222.0 ,
SectorType : "ADJUSTABLE"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 5990939.0 ,
SectorType : "FIXED, OID"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 2E-05 ,
MarketNotion : 5809637.0 ,
SectorType : "EURO-DOLLAR"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 0.00377 ,
MarketNotion : 1435870.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Airlines" ,
IndustrySector : "Consumer" ,
KRD : 6E-05 ,
MarketNotion : 47338486.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 1.46433 ,
MarketNotion : 42605156.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 0.0 ,
MarketNotion : 41030865.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 6E-05 ,
MarketNotion : 30346443.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Retail" ,
IndustrySector : "Consumer, Cyclical" ,
KRD : 0.20296 ,
MarketNotion : 25111160.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Sovereign" ,
IndustrySector : "Government" ,
KRD : 0.05421 ,
MarketNotion : 23189929.0 ,
SectorType : "US GOVERNMENT"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.00031 ,
MarketNotion : 19365191.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 16235303.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : 0.00087 ,
MarketNotion : 11072448.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : -0.00063 ,
MarketNotion : 7550053.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : -1E-05 ,
MarketNotion : 6372222.0 ,
SectorType : "ADJUSTABLE"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 5990939.0 ,
SectorType : "FIXED, OID"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 2E-05 ,
MarketNotion : 5809637.0 ,
SectorType : "EURO-DOLLAR"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 0.00377 ,
MarketNotion : 1435870.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Airlines" ,
IndustrySector : "Consumer" ,
KRD : 6E-05 ,
MarketNotion : 47338486.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 1.46433 ,
MarketNotion : 42605156.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Insurance" ,
IndustrySector : "Financial" ,
KRD : 0.0 ,
MarketNotion : 41030865.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 6E-05 ,
MarketNotion : 30346443.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Retail" ,
IndustrySector : "Consumer, Cyclical" ,
KRD : 0.20296 ,
MarketNotion : 25111160.0 ,
SectorType : "PUBLIC"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Sovereign" ,
IndustrySector : "Government" ,
KRD : 0.05421 ,
MarketNotion : 23189929.0 ,
SectorType : "US GOVERNMENT"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.00031 ,
MarketNotion : 19365191.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 16235303.0 ,
SectorType : "FIXED"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : 0.00087 ,
MarketNotion : 11072448.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Engineering&Construction" ,
IndustrySector : "Industrial" ,
KRD : -0.00063 ,
MarketNotion : 7550053.0 ,
SectorType : "GLOBAL"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : -1E-05 ,
MarketNotion : 6372222.0 ,
SectorType : "ADJUSTABLE"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Municipal" ,
IndustrySector : "Government" ,
KRD : 0.0 ,
MarketNotion : 5990939.0 ,
SectorType : "FIXED, OID"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 2E-05 ,
MarketNotion : 5809637.0 ,
SectorType : "EURO-DOLLAR"
}));
this .push(new MarketRecord({
Date : "new" ,
IndustryGroup : "Banks" ,
IndustrySector : "Financial" ,
KRD : 0.00377 ,
MarketNotion : 1435870.0 ,
SectorType : "GLOBAL"
}));
};
}
ts コピー import 'igniteui-webcomponents-grids/grids/combined' ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
import { IgcGridComponent } from 'igniteui-webcomponents-grids/grids' ;
import { defineComponents, IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent, registerIconFromText } from 'igniteui-webcomponents' ;
import { MarketData } from './MarketData' ;
import "./index.css" ;
defineComponents(IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent);
export class Sample {
private grid: IgcGridComponent;
private searchBox: IgcInputComponent;
private searchIcon: IgcIconComponent;
private clearIcon: IgcIconComponent;
private nextIconButton: IgcIconButtonComponent;
private prevIconButton: IgcIconButtonComponent;
private caseSensitiveChip: IgcChipComponent;
private exactMatchChip: IgcChipComponent;
private data: MarketData;
private _bind: () => void ;
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
this .nextSearch = this .nextSearch.bind(this );
this .prevSearch = this .prevSearch.bind(this );
this .clearSearch = this .clearSearch.bind(this );
const prevIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z'></path></svg>" ;
const nextIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z'></path></svg>" ;
const clearIconText = "<svg width='24' height='24' viewBox='0 0 24 24' title='Clear'><path d='M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'></path></svg>" ;
const searchIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z' /></svg>" ;
registerIconFromText("prev" , prevIconText, "material" );
registerIconFromText("next" , nextIconText, "material" );
registerIconFromText("clear" , clearIconText, "material" );
registerIconFromText("search" , searchIconText, "material" );
var searchIcon = this .searchIcon = document .getElementById('searchIcon' ) as IgcIconComponent;
var nextIconButton = this .nextIconButton = document .getElementById('nextIconBtn' ) as IgcIconButtonComponent;
var prevIconButton = this .prevIconButton = document .getElementById('prevIconBtn' ) as IgcIconButtonComponent;
this .caseSensitiveChip = document .getElementById('caseSensitiveChip' ) as IgcChipComponent;
this .exactMatchChip = document .getElementById('exactMatchChip' ) as IgcChipComponent;
var searchBox = this .searchBox = document .getElementById('searchBox' ) as IgcInputComponent;
this .data = new MarketData();
this ._bind = () => {
grid.data = this .data;
searchBox.addEventListener("keydown" , (evt ) => { this .onSearchKeydown(evt); });
this .searchBox.addEventListener("igcInput" , (evt ) => {
this .searchIcon.name = evt.detail ? 'clear' : 'search' ;
this .grid.findNext(evt.detail, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
});
nextIconButton.addEventListener("click" , this .nextSearch);
prevIconButton.addEventListener("click" , this .prevSearch);
searchIcon.addEventListener("click" , this .clearSearch);
}
this ._bind();
}
public onSearchKeydown (evt: KeyboardEvent ) {
if (evt.key === 'Enter' || evt.key === 'ArrowDown' ) {
evt.preventDefault();
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
} else if (evt.key === 'ArrowUp' ) {
evt.preventDefault();
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
}
public prevSearch ( ) {
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public clearSearch ( ) {
this .searchBox.value = "" ;
this .grid.clearSearch();
this .searchIcon.name = 'search' ;
}
}
new Sample();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Sample | Ignite UI | Web Components | infragistics</title >
<meta charset ="UTF-8" />
<link rel ="shortcut icon" href ="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel ="stylesheet" href ="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel ="stylesheet" href ="/src/index.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample" >
<div class ="container vertical" >
<div style ="margin-bottom: 1rem" >
<igc-input id ="searchBox" name ="searchBox" >
<igc-icon id ="searchIcon" slot ="prefix" name ="search" collection ="material" > </igc-icon >
<div slot ="suffix" >
<igc-chip selectable ="true" id ="caseSensitiveChip" > Case Sensitive</igc-chip >
<igc-chip selectable ="true" id ="exactMatchChip" > Exact Match</igc-chip >
</div >
<div slot ="suffix" >
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
</div >
</igc-input >
</div >
<igc-grid class ="gridSize" auto-generate ="false" id ="grid" name ="grid" allow-filtering ="true" height ="100%" width ="100%" >
<igc-column field ="IndustrySector" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="IndustryGroup" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="SectorType" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="KRD" data-type ="number" sortable ="true" > </igc-column >
<igc-column field ="MarketNotion" data-type ="number" sortable ="true" > </igc-column >
</igc-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
.gridSize {
--ig-size: var (--ig-size-small);
}
css コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Web Components 検索の使用
Grid のセットアップ
グリッドを作成してからデータをバインドします。コンポーネントにカスタム スタイルも追加しました。
.gridSize {
--ig-size: var (--ig-size-small);
}
css
<igc-grid id ="grid1" class ="gridSize" auto-generate ="false" allow-filtering ="true" >
<igc-column field ="IndustrySector" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="IndustryGroup" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="SectorType" data-type ="string" sortable ="true" > </igc-column >
<igc-column field ="KRD" data-type ="number" sortable ="true" > </igc-column >
<igc-column field ="MarketNotion" data-type ="number" sortable ="true" > </igc-column >
<igc-column field ="Date" data-type ="date" sortable ="true" > </igc-column >
</igc-grid >
html
では、IgcGridComponent
の検索 API の準備をしましょう。検索したテキストの保存、また大文字小文字の区別や完全一致 (またはそのいずれか) に使用するプロパティを作成できます。
private grid: IgcGridComponent;
private searchBox: IgcInputComponent;
private searchIcon: IgcIconComponent;
private clearIcon: IgcIconComponent;
private nextIconButton: IgcIconButtonComponent;
private prevIconButton: IgcIconButtonComponent;
private caseSensitiveChip: IgcChipComponent;
private exactMatchChip: IgcChipComponent;
typescript
Web Components 検索ボックス入力
検索入力を作成します。input 要素を取得することで、その現在の値を取得できます。これにより、IgcGridComponent
の findNext
メソッドと findPrev
メソッドを使用して、SearchText
が出現するすべての箇所をハイライト表示し、(呼び出したメソッドに応じて) 次 / 前の箇所にスクロールできるようになります。
findNext
と findPrev
メソッドの両方に 3 つの引数があります。
Text
: string (検索テキスト)
(オプション) CaseSensitive
: boolean (検索で完全一致するかどうか、デフォルト値は false)。
(オプション) ExactMatch
: boolean (検索で完全一致するかどうか、デフォルト値は false)。
完全一致で検索した場合、検索 API は SearchText
と完全一致 (大文字小文字の区別を含む) するセル値のみ結果としてハイライト表示します。たとえば、文字列 'software' と 'Software' は大文字小文字を区別しない場合は完全一致となります。
上記のメソッドは number 値を返します (IgcGridComponent
で指定した文字列が含まれる回数)。
<igc-input id ="searchBox" name ="searchBox" >
</igc-input >
html
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
this .searchBox = document .getElementById('searchBox' ) as IgcInputComponent;
grid.data = new MarketData();
}
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, false , false );
}
ts
検索ボタンの追加
ボタンの各クリック イベント ハンドラー内で findNext
と findPrev
メソッドを呼び出して検索や検索結果をナビゲーションするためのボタンを作成します。
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
html
constructor ( ) {
var nextIconButton = document .getElementById('nextIconBtn' ) as IgcIconButtonComponent;
var prevIconButton = document .getElementById('prevIconBtn' ) as IgcIconButtonComponent;
nextIconButton.addEventListener("click" , this .nextSearch);
prevIconButton.addEventListener("click" , this .prevSearch);
}
public prevSearch ( ) {
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
ts
キーボード検索の追加
ユーザーは矢印キーと Enter キーで結果を移動できます。PreventDefault
メソッドのデフォルト キャレットの移動を防止する検索入力の keydown イベントを処理し、ユーザーが押したキーに基づいて findNext
/findPrev
メソッドを呼び出します。
<input id ="searchBox" name ="searchBox" />
html
constructor ( ) {
searchBox.addEventListener("keydown" , (evt ) => { this .onSearchKeydown(evt); });
this .searchBox.addEventListener("igcInput" , (evt ) => {
this .searchIcon.name = evt.detail ? 'clear' : 'search' ;
this .grid.findNext(evt.detail, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
});
}
public onSearchKeydown (evt: KeyboardEvent ) {
if (evt.key === 'Enter' || evt.key === 'ArrowDown' ) {
evt.preventDefault();
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
} else if (evt.key === 'ArrowUp' ) {
evt.preventDefault();
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
}
}
typescript
大文字と小文字の区別と完全一致
次に完全一致の検索で大文字と小文字を区別するかどうかをユーザーが選択できるようにします。この目的のために、単純なチェックボックス入力を使用し、その change
イベントにバインドして、チェックボックスの checked
状態を使用できます。
<span > Case sensitive</span >
<input id ="case" type ="checkbox" >
<span > Exact match</span >
<input id ="exact" type ="checkbox" >
html
constructor ( ) {
const case = document .getElementById("case" ) as HTMLInputElement;
const exact = document .getElementById("exact" ) as HTMLInputElement;
case .addEventListener("change" , this .updateSearch);
exact.addEventListener("change" , this .updateSearch);
}
public updateSearch ( ) {
const search1 = document .getElementById("search1" ) as HTMLInputElement;
const case = document .getElementById("case" ) as HTMLInputElement;
const exact = document .getElementById("exact" ) as HTMLInputElement;
const grid = document .getElementById("grid" ) as IgcGridComponent;
grid.findNext(search1.value, case .checked, exact.checked);
}
typescript
保持
IgcGridComponent
のフィルターやソート、レコードの追加や削除をする場合を想定します。そのような処理の後、現在の検索が自動的に更新されて SearchText
に一致するテキストが保持されます。更に検索がページングで動作し、IgcGridComponent
の PerPage
プロパティの変更時もハイライト表示が保持されます。
アイコンの追加
その他のコンポーネントを使用するためにユーザー インターフェイスを作成し、検索バー全体のデザインを向上します。検索入力の左側に検索または削除アイコン、検索オプションのチップ、右側にはマテリアル デザイン アイコンと Ripple スタイルのボタンを組み合わせたナビゲーションを表示できます。入力グループ内のコンポーネントをラップしてより洗練されたデザインにすることができます。
import { defineComponents, IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent, registerIconFromText } from "igniteui-webcomponents" ;
defineComponents(IgcInputComponent, IgcChipComponent, IgcIconComponent, IgcIconButtonComponent);
typescript
テンプレートを新しいコンポーネントで更新します。
<igc-input id ="searchBox" name ="searchBox" >
<igc-icon id ="searchIcon" slot ="prefix" name ="search" collection ="material" > </igc-icon >
<div slot ="suffix" >
<igc-chip selectable ="true" id ="caseSensitiveChip" > Case Sensitive</igc-chip >
<igc-chip selectable ="true" id ="exactMatchChip" > Exact Match</igc-chip >
</div >
<div slot ="suffix" >
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
</div >
</igc-input >
html
constructor ( ) {
const prevIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z'></path></svg>" ;
const nextIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z'></path></svg>" ;
const clearIconText = "<svg width='24' height='24' viewBox='0 0 24 24' title='Clear'><path d='M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'></path></svg>" ;
const searchIconText = "<svg width='24' height='24' viewBox='0 0 24 24'><path d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z' /></svg>" ;
registerIconFromText("prev" , prevIconText, "material" );
registerIconFromText("next" , nextIconText, "material" );
registerIconFromText("clear" , clearIconText, "material" );
registerIconFromText("search" , searchIconText, "material" );
}
typescript
右側の入力グループに以下の目的で別のコンテナーを作成します。
以下は CaseSensitive
と ExactMatch
を切り替えるチップを表示する方法です。プロパティに基づいて色が変わる 2 つのチップでチェックボックスを 置き換えます。チップをクリックすると、どちらのチップがクリックされたかによって各ハンドラーを呼び出します。
<div slot ="suffix" >
<igc-chip selectable ="true" id ="caseSensitiveChip" > Case Sensitive</igc-chip >
<igc-chip selectable ="true" id ="exactMatchChip" > Exact Match</igc-chip >
</div >
html
constructor ( ) {
const input = document .getElementById("searchBox" ) as IgcInputComponent;
input.addEventListener("change" , this .updateSearch);
}
public updateSearch ( ) {
const grid = document .getElementById('grid' ) as IgcGridComponent;
const caseSensitiveChip = document .getElementById('caseSensitiveChip' ) as IgcChipComponent;
const exactMatchChip = document .getElementById('exactMatchChip' ) as IgcChipComponent;
grid.findNext(input.value, caseSensitiveChip.selected, exactMatchChip.selected);
}
ts
検索ナビゲーション ボタンは、マテリアルアイコンを使用して入力を Ripple スタイルボタンにします。click イベントのハンドラーはそのままで findNext
/findPrev
メソッドを呼び出します。
<div slot ="suffix" >
<igc-icon-button id ="prevIconBtn" variant ="flat" name ="prev" collection ="material" > </igc-icon-button >
<igc-icon-button id ="nextIconBtn" variant ="flat" name ="next" collection ="material" > </igc-icon-button >
</div >
html
constructor ( ) {
const nextIconButton = this .nextIconButton = document .getElementById('nextIconBtn' ) as IgcIconButtonComponent;
const prevIconButton = this .prevIconButton = document .getElementById('prevIconBtn' ) as IgcIconButtonComponent;
nextIconButton.addEventListener("click" , this .nextSearch);
prevIconButton.addEventListener("click" , this .prevSearch);
}
typescript
public nextSearch ( ) {
this .grid.findNext(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
public prevSearch ( ) {
this .grid.findPrev(this .searchBox.value, this .caseSensitiveChip.selected, this .exactMatchChip.selected);
}
ts
既知の問題と制限
制限
説明
テンプレートを使用したセル内の検索
検索機能のハイライト表示が、デフォルトのセルテンプレートに対してのみ機能する問題。カスタム セル テンプレートを含む列がある場合、ハイライト表示が機能しないため、列フォーマッタなどの代替アプローチを使用するか、searchable
(検索可能な) プロパティを false に設定します。
リモート仮想化
リモート仮想化の使用時に検索が正しく動作しません。
セル テキストが切れる問題
セル内のテキストが長すぎるために検索テキストが省略記号によって切れている場合も、セルまでスクロールして一致カウントに含まれますが、ハイライト表示はされません。
API リファレンス
このトピックでは、IgcGridComponent
にカスタム検索バーを実装し、更に検索結果を移動する際の機能を追加しました。アイコン、チップ、入力などその他の Ignite UI for Web Components も使用しています。以下は検索 API です。
IgcGridComponent
メソッド:
IgcColumnComponent
プロパティ:
その他のコンポーネント (またはそのいずれか) で使用した API:
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。