Blazor Grid 検索フィルター
Blazor Grid の Ignite UI for Blazor 検索フィルター機能を使用すると、データのコレクション内の値を検索するプロセスが可能になります。この機能のセットアップが簡単になり、検索入力ボックス、ボタン、キーボード ナビゲーション、その他の便利な機能を使用して実装できるため、ユーザー エクスペリエンスがさらに向上します。ブラウザーにはネイティブなコンテンツ検索機能がありますが、ほとんどの場合で IgbGrid
は表示範囲外の行列を仮想化します。そのため、ネイティブ ブラウザー検索は DOM の一部でないため仮想化セルでデータを検索できません。IgbGrid
では、Blazor Material テーブル ベースのグリッドの拡張により、検索 API を使用した仮想コンテンツ の検索が可能です。
すぐに使用できる機能のフルセット は、ページング、ソート、フィルタリング、編集、グループ化から行と列の仮想化まで、あらゆる機能をカバーします。.NET 開発者には制限はありません。
Blazor 検索の例
次の例は、すべての列と行を検索できる検索入力ボックスと、各列の特定のフィルタリング オプションを備えた IgbGrid
を表しています。
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;
using IgniteUI.Blazor.Controls;
namespace Infragistics.Samples
{
public class Program
{
public static async 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) });
builder.Services.AddIgniteUIBlazor(
typeof (IgbGridModule),
typeof (IgbGridColumnOptionsModule),
typeof (IgbInputModule),
typeof (IgbIconButtonModule),
typeof (IgbIconModule)
);
await builder.Build().RunAsync();
}
}
}
cs コピー using System;
using System.Collections;
using System.Collections.Generic;
namespace Infragistics.Samples
{
public class MarketRecord
{
public string IndustryGroup { get ; set ; }
public string IndustrySector { get ; set ; }
public string SectorType { get ; set ; }
public double KRD { get ; set ; }
public double MarketNotion { get ; set ; }
public string Date { get ; set ; }
}
public class MarketData
{
public static List<MarketRecord> GetData ( )
{
var data = new List<MarketRecord>() {
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Airlines" ,
IndustrySector = "Consumer" ,
KRD = 6E-05 ,
MarketNotion = 47338486.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Insurance" ,
IndustrySector = "Financial" ,
KRD = 1.46433 ,
MarketNotion = 42605156.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Insurance" ,
IndustrySector = "Financial" ,
KRD = 0.0 ,
MarketNotion = 41030865.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 6E-05 ,
MarketNotion = 30346443.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Retail" ,
IndustrySector = "Consumer, Cyclical" ,
KRD = 0.20296 ,
MarketNotion = 25111160.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Sovereign" ,
IndustrySector = "Government" ,
KRD = 0.05421 ,
MarketNotion = 23189929.0 ,
SectorType = "US GOVERNMENT"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.00031 ,
MarketNotion = 19365191.0 ,
SectorType = "FIXED"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.0 ,
MarketNotion = 16235303.0 ,
SectorType = "FIXED"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Engineering&Construction" ,
IndustrySector = "Industrial" ,
KRD = 0.00087 ,
MarketNotion = 11072448.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Engineering&Construction" ,
IndustrySector = "Industrial" ,
KRD = -0.00063 ,
MarketNotion = 7550053.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = -1E-05 ,
MarketNotion = 6372222.0 ,
SectorType = "ADJUSTABLE"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.0 ,
MarketNotion = 5990939.0 ,
SectorType = "FIXED, OID"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 2E-05 ,
MarketNotion = 5809637.0 ,
SectorType = "EURO-DOLLAR"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 0.00377 ,
MarketNotion = 1435870.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Airlines" ,
IndustrySector = "Consumer" ,
KRD = 6E-05 ,
MarketNotion = 47338486.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Insurance" ,
IndustrySector = "Financial" ,
KRD = 1.46433 ,
MarketNotion = 42605156.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Insurance" ,
IndustrySector = "Financial" ,
KRD = 0.0 ,
MarketNotion = 41030865.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 6E-05 ,
MarketNotion = 30346443.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Retail" ,
IndustrySector = "Consumer, Cyclical" ,
KRD = 0.20296 ,
MarketNotion = 25111160.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Sovereign" ,
IndustrySector = "Government" ,
KRD = 0.05421 ,
MarketNotion = 23189929.0 ,
SectorType = "US GOVERNMENT"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.00031 ,
MarketNotion = 19365191.0 ,
SectorType = "FIXED"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.0 ,
MarketNotion = 16235303.0 ,
SectorType = "FIXED"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Engineering&Construction" ,
IndustrySector = "Industrial" ,
KRD = 0.00087 ,
MarketNotion = 11072448.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Engineering&Construction" ,
IndustrySector = "Industrial" ,
KRD = -0.00063 ,
MarketNotion = 7550053.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = -1E-05 ,
MarketNotion = 6372222.0 ,
SectorType = "ADJUSTABLE"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.0 ,
MarketNotion = 5990939.0 ,
SectorType = "FIXED, OID"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 2E-05 ,
MarketNotion = 5809637.0 ,
SectorType = "EURO-DOLLAR"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 0.00377 ,
MarketNotion = 1435870.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Airlines" ,
IndustrySector = "Consumer" ,
KRD = 6E-05 ,
MarketNotion = 47338486.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Insurance" ,
IndustrySector = "Financial" ,
KRD = 1.46433 ,
MarketNotion = 42605156.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Insurance" ,
IndustrySector = "Financial" ,
KRD = 0.0 ,
MarketNotion = 41030865.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 6E-05 ,
MarketNotion = 30346443.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Retail" ,
IndustrySector = "Consumer, Cyclical" ,
KRD = 0.20296 ,
MarketNotion = 25111160.0 ,
SectorType = "PUBLIC"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Sovereign" ,
IndustrySector = "Government" ,
KRD = 0.05421 ,
MarketNotion = 23189929.0 ,
SectorType = "US GOVERNMENT"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.00031 ,
MarketNotion = 19365191.0 ,
SectorType = "FIXED"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.0 ,
MarketNotion = 16235303.0 ,
SectorType = "FIXED"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Engineering&Construction" ,
IndustrySector = "Industrial" ,
KRD = 0.00087 ,
MarketNotion = 11072448.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Engineering&Construction" ,
IndustrySector = "Industrial" ,
KRD = -0.00063 ,
MarketNotion = 7550053.0 ,
SectorType = "GLOBAL"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = -1E-05 ,
MarketNotion = 6372222.0 ,
SectorType = "ADJUSTABLE"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Municipal" ,
IndustrySector = "Government" ,
KRD = 0.0 ,
MarketNotion = 5990939.0 ,
SectorType = "FIXED, OID"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 2E-05 ,
MarketNotion = 5809637.0 ,
SectorType = "EURO-DOLLAR"
},
new MarketRecord() {
Date = "new" ,
IndustryGroup = "Banks" ,
IndustrySector = "Financial" ,
KRD = 0.00377 ,
MarketNotion = 1435870.0 ,
SectorType = "GLOBAL"
}
};
return data;
}
}
}
cs コピー
@using IgniteUI.Blazor.Controls
<style >
.gridSize {
--ig-size: var (--ig-size-small);
}
</style >
<div class ="container vertical" >
@ if (marketData != null )
{
<div style ="margin-bottom: 1rem" >
<IgbInput ValueChanging ="OnValueChanging" Value ="@ searchText " @onkeydown ="OnSearchKeyDown" >
@ if (searchText.Length == 0 )
{
<IgbIcon @ref ="searchIconRef" slot ="prefix" IconName ="search" Collection ="material" / >
}
@ if (searchText.Length > 0 )
{
<IgbIcon slot ="prefix" IconName ="clear" Collection ="material" @onclick ="ClearSearch" / >
}
<div class ="chips" slot ="suffix" >
<IgbChip Selectable =true SelectedChanged ="UpdateCase" >
Case Sensitive
</IgbChip >
<IgbChip Selectable =true SelectedChanged ="UpdateExactSearch" >
Exact Match
</IgbChip >
</div >
<div class ="searchButtons" slot ="suffix" >
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="PrevSearch" >
<IgbIcon IconName ="prev" Collection ="material" / >
</IgbIconButton >
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="NextSearch" >
<IgbIcon IconName ="next" Collection ="material" />
</IgbIconButton >
</div >
</IgbInput >
</div >
<div class ="container vertical" >
<IgbGrid @ref =grid Class ="gridSize" Width ="100%" Height ="100%" AllowFiltering =true AutoGenerate =false Data =marketData >
<IgbColumn Field ="IndustrySector" Header ="Industry Sector" DataType ="GridColumnDataType.String" Sortable =true > </IgbColumn >
<IgbColumn Field ="IndustryGroup" Header ="Industry Group" DataType ="GridColumnDataType.String" Sortable =true > </IgbColumn >
<IgbColumn Field ="SectorType" Header ="Sector Type" DataType ="GridColumnDataType.String" Sortable =true > </IgbColumn >
<IgbColumn Field ="KRD" DataType ="GridColumnDataType.Number" Sortable =true > </IgbColumn >
<IgbColumn Field ="MarketNotion" Header ="Market Notion" DataType ="GridColumnDataType.Number" Sortable =true > </IgbColumn >
</IgbGrid >
</div >
}
</div >
@code {
private List <MarketRecord > marketData;
private IgbGrid grid;
public bool caseSensitive = false ;
public bool exactMatch = false ;
public string searchText = "" ;
private IgbIcon searchIconRef { get ; set ; }
const string searchIcon = " <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 > " ;
const string prevIcon = " <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 string nextIcon = " <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 string clearIcon = " <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 > " ;
protected override void OnInitialized ( )
{
this .marketData = MarketData.GetData();
}
protected override void OnAfterRender (bool firstRender )
{
if (this .searchIconRef != null && firstRender)
{
this .searchIconRef.EnsureReady().ContinueWith(new Action<Task>((e) =>
{
this .searchIconRef.RegisterIconFromTextAsync("search" , searchIcon, "material" );
this .searchIconRef.RegisterIconFromTextAsync("prev" , prevIcon, "material" );
this .searchIconRef.RegisterIconFromTextAsync("next" , nextIcon, "material" );
this .searchIconRef.RegisterIconFromTextAsync("clear" , clearIcon, "material" );
}));
}
}
private void OnSearchKeyDown (KeyboardEventArgs evt )
{
if (evt.Key == "Enter" && !evt.ShiftKey) {
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
} else if (evt.Key == "Enter" ) {
this .grid.FindPrevAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
}
public void OnValueChanging (string newValue )
{
this .searchText = newValue;
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void PrevSearch ( )
{
this .grid.FindPrevAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void NextSearch ( )
{
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void ClearSearch ( )
{
this .searchText = "" ;
this .grid.ClearSearchAsync();
}
public void UpdateCase (bool selected ) {
this .caseSensitive = selected;
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void UpdateExactSearch (bool selected ) {
this .exactMatch = selected;
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
}
razor コピー
.gridSize {
--ig-size: var (--ig-size-small);
}
css コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Blazorツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Blazor 検索の使用
Grid のセットアップ
グリッドを作成してからデータをバインドします。コンポーネントにカスタム スタイルも追加しました。
.gridSize {
--ig-size: var (--ig-size-small);
}
css
<IgbGrid @ref =grid Class ="gridSize" Width ="100%" Height ="480px" AllowFiltering =true AutoGenerate =false Data =marketData >
<IgbColumn Field ="IndustrySector" DataType ="GridColumnDataType.String" Sortable =true > </IgbColumn >
<IgbColumn Field ="IndustryGroup" DataType ="GridColumnDataType.String" Sortable =true > </IgbColumn >
<IgbColumn Field ="SectorType" DataType ="GridColumnDataType.String" Sortable =true > </IgbColumn >
<IgbColumn Field ="KRD" DataType ="GridColumnDataType.Number" Sortable =true > </IgbColumn >
<IgbColumn Field ="MarketNotion" DataType ="GridColumnDataType.Number" Sortable =true > </IgbColumn >
</IgbGrid >
@code {
protected override void OnInitialized ( )
{
base .OnInitialized();
this .marketData = MarketData.GetData();
}
}
razor
では、IgbGrid
の検索 API の準備をしましょう。検索したテキストの保存、また大文字小文字の区別や完全一致 (またはそのいずれか) に使用するプロパティを作成できます。
public string searchText = "";
public bool caseSensitive = false;
public bool exactMatch = false;
razor
Blazor 検索ボックス入力
検索入力を作成します。新しく作成した入力の Value
プロパティに SearchText
をバインドし、ValueChanging
イベントをサブスクライブすることで、ユーザーによるすべての SearchText
の変更を検出できます。これによって IgbGrid
の FindNext
と FindPrev
メソッドを使用して SearchText
のすべての出現を強調し、次へまたは前 (呼び出すメソッドに基づいて) へスクロールできます。
FindNext
と FindPrev
メソッドの両方に 3 つの引数があります。
Text
: string (検索テキスト)
(オプション) CaseSensitive
: boolean (検索で完全一致するかどうか、デフォルト値は false)。
(オプション) ExactMatch
: boolean (検索で完全一致するかどうか、デフォルト値は false)。
完全一致で検索した場合、検索 API は SearchText
と完全一致 (大文字小文字の区別を含む) するセル値のみ結果としてハイライト表示します。たとえば、文字列 'software' と 'Software' は大文字小文字を区別しない場合は完全一致となります。
上記のメソッドは number 値を返します (IgbGrid
で指定した文字列が含まれる回数)。
<IgbInput ValueChanging ="valueChanging" Value ="@ searchText " />
razor
検索ボタンの追加
ボタンの各クリック イベント ハンドラー内で FindNext
と FindPrev
メソッドを呼び出して検索や検索結果をナビゲーションするためのボタンを作成します。
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="PrevSearch" >
<IgbIcon IconName ="prev" Collection ="material" / >
</IgbIconButton >
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="NextSearch" >
<IgbIcon IconName ="next" Collection ="material" />
</IgbIconButton >
@code {
private IgbGrid grid;
public void PrevSearch ( )
{
this .grid.FindPrevAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void NextSearch ( )
{
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
}
razor
キーボード検索の追加
ユーザーは矢印キーと Enter キーで結果を移動できます。PreventDefault
メソッドのデフォルト キャレットの移動を防止する検索入力の keydown イベントを処理し、ユーザーが押したキーに基づいて FindNext
/FindPrev
メソッドを呼び出します。
ユーザーは Enter キーで結果を移動できます。これを実現するために、検索の keydown イベントを処理し、ユーザーが Shift キーを押したかどうかに応じて FindNext
/FindPrev
メソッドを呼び出すことができます。
<IgbInput ValueChanging ="valueChanging" Value ="@ searchText " @onkeydown ="OnSearchKeyDown" / >
@code {
private void OnSearchKeyDown (KeyboardEventArgs evt )
{
if (evt.Key == "Enter" && !evt.ShiftKey) {
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
} else if (evt.Key == "Enter" ) {
this .grid.FindPrevAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
}
}
razor
大文字と小文字の区別と完全一致
次に完全一致の検索で大文字と小文字を区別するかどうかをユーザーが選択できるようにします。この目的のために、単純な選択可能な Chips
を使用し、SelectedChanged
イベントにバインドして、ユーザーがいつチップを操作したかを判断できます。
<IgbChip Selectable =true SelectedChanged ="UpdateCase" >
Case Sensitive
</IgbChip >
<IgbChip Selectable =true SelectedChanged ="UpdateExactSearch" >
Exact Match
</IgbChip >
@code {
public void UpdateCase (bool selected ) {
this .caseSensitive = selected;
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void UpdateExactSearch (bool selected ) {
this .exactMatch = selected;
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
}
razor
保持
IgbGrid
のフィルターやソート、レコードの追加や削除をする場合を想定します。そのような処理の後、現在の検索が自動的に更新されて SearchText
に一致するテキストが保持されます。更に検索がページングで動作し、IgbGrid
の PerPage
プロパティの変更時もハイライト表示が保持されます。
アイコンの追加
その他のコンポーネントを使用するためにユーザー インターフェイスを作成し、検索バー全体のデザインを向上します。検索入力の左側に検索または削除アイコン、検索オプションのチップ、右側にはマテリアル デザイン アイコンと Ripple スタイルのボタンを組み合わせたナビゲーションを表示できます。
IgbInput
、IgbIcon
、IgbIconButton
、IgbChip
のモジュールを使用します。
// eg. Program.cs register the following:
builder.Services.AddIgniteUIBlazor(
typeof(IgbGridModule),
typeof(IgbInputModule),
typeof(IgbIconButtonModule),
typeof(IgbIconModule)
);
razor
@code {
private IgbIcon searchIconRef { get ; set ; }
const string searchIcon = " <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 > " ;
const string prevIcon = " <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 string nextIcon = " <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 string clearIcon = " <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 > " ;
protected override void OnAfterRender (bool firstRender )
{
if (this .searchIconRef != null && firstRender)
{
this .searchIconRef.EnsureReady().ContinueWith(new Action<Task>((e) =>
{
this .searchIconRef.RegisterIconFromTextAsync("search" , searchIcon, "material" );
this .searchIconRef.RegisterIconFromTextAsync("prev" , prevIcon, "material" );
this .searchIconRef.RegisterIconFromTextAsync("next" , nextIcon, "material" );
this .searchIconRef.RegisterIconFromTextAsync("clear" , clearIcon, "material" );
}));
}
}
}
razor
テンプレートを新しいコンポーネントで更新します。
IgbInput
内のすべてのコンポーネントをラップします。左側で検索と 削除/クリア アイコンを切り替えます (検索入力が空かどうかに基づきます)。中央に入力を配置します。更に削除アイコンがクリックされたときに SearchText
を更新し、IgbGrid
の ClearSearch
メソッドを呼び出してハイライト表示をクリアします。
<IgbInput ValueChanging ="OnValueChanging" Value ="@ searchText " @onkeydown ="OnSearchKeyDown" >
@ if (searchText.Length == 0 )
{
<IgbIcon @ref ="searchIconRef" slot ="prefix" IconName ="search" Collection ="material" / >
}
@ if (searchText.Length > 0 )
{
<IgbIcon slot ="prefix" IconName ="clear" Collection ="material" @onclick ="ClearSearch" / >
}
<div class ="chips" slot ="suffix" >
<IgbChip Selectable =true SelectedChanged ="UpdateCase" >
Case Sensitive
</IgbChip >
<IgbChip Selectable =true SelectedChanged ="UpdateExactSearch" >
Exact Match
</IgbChip >
</div >
<div class ="searchButtons" slot ="suffix" >
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="PrevSearch" >
<IgbIcon IconName ="prev" Collection ="material" / >
</IgbIconButton >
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="NextSearch" >
<IgbIcon IconName ="next" Collection ="material" />
</IgbIconButton >
</div >
</IgbInput >
@code {
public void clearSearch ( )
{
this .searchText = "" ;
this .grid.ClearSearchAsync();
}
}
razor
右側の入力グループに以下の目的で別のコンテナーを作成します。
以下は CaseSensitive
と ExactMatch
プロパティを切り替えるチップを表示する方法です。チェックボックスの代わりにスタイリッシュなチップを 2 つ表示します。チップをクリックすると、どちらのチップがクリックされたかによって各ハンドラーを呼び出します。
<div class ="chips" slot ="suffix" >
<IgbChip Selectable =true SelectedChanged ="UpdateCase" >
Case Sensitive
</IgbChip >
<IgbChip Selectable =true SelectedChanged ="UpdateExactSearch" >
Exact Match
</IgbChip >
</div >
@code {
public void UpdateCase (bool selected ) {
this .caseSensitive = selected;
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void UpdateExactSearch (bool selected ) {
this .exactMatch = selected;
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
}
razor
検索ナビゲーションボタンには、マテリアル アイコン付きのリップル スタイル ボタンを追加しています。click イベントのハンドラーはそのままで FindNext
/FindPrev
メソッドを呼び出します。
<div class ="searchButtons" slot ="suffix" >
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="PrevSearch" >
<IgbIcon IconName ="prev" Collection ="material" / >
</IgbIconButton >
<IgbIconButton Variant ="IconButtonVariant.Flat" @onclick ="NextSearch" >
<IgbIcon IconName ="next" Collection ="material" />
</IgbIconButton >
</div >
@code {
public void PrevSearch ( )
{
this .grid.FindPrevAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
public void NextSearch ( )
{
this .grid.FindNextAsync(this .searchText, this .caseSensitive, this .exactMatch);
}
}
razor
既知の問題と制限
制限
説明
テンプレートを使用したセル内の検索
検索機能のハイライト表示が、デフォルトのセルテンプレートに対してのみ機能する問題。カスタム セル テンプレートを含む列がある場合、ハイライト表示が機能しないため、列フォーマッタなどの代替アプローチを使用するか、Searchable
(検索可能な) プロパティを false に設定します。
リモート仮想化
リモート仮想化の使用時に検索が正しく動作しません。
セル テキストが切れる問題
セル内のテキストが長すぎるために検索テキストが省略記号によって切れている場合も、セルまでスクロールして一致カウントに含まれますが、ハイライト表示はされません。
API リファレンス
このトピックでは、IgbGrid
にカスタム検索バーを実装し、更に検索結果を移動する際の機能を追加しました。アイコン、チップ、入力などその他の Ignite UI for Blazor も使用しています。以下は検索 API です。
IgbGrid
メソッド:
IgbColumn
プロパティ:
その他のコンポーネント (またはそのいずれか) で使用した API:
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。