Blazor Grid ソート
Blazor Grid の Ignite UI for Blazor データ ソート機能は列ごとのレベルで有効になっています。つまり、IgbGrid にはソート可能な列とソート不可能な列を混在させることができます。Blazor でソートを実行すると、指定した条件に基づいてレコードの表示順序を変更できます。
Blazor Grid ソート概要の例
以下のように Sortable 入力を使用します。IgbGrid のソートで、SortingIgnoreCase プロパティを設定して大文字と小文字を区別するソートができます。
<IgbColumn Field="Title" Sortable="true"></IgbColumn>
ソート インジケーター
ソートされた列数が一定数以上ある場合、ソート順の指定がないと混乱する可能性があります。
IgbGrid は、ソートされた各列のインデックスを示すことにより、この問題の解決策を提供します。
API でのソート
IgbGrid Sort メソッドを使用し、列または複数の列を IgbGrid API でソートできます。
@code {
this.grid.SortAsync(new IgbSortingExpression[]
{
new IgbSortingExpression
{
FieldName = "CompanyName",
Dir = SortingDirection.Asc
},
new IgbSortingExpression
{
FieldName = "Country",
Dir = SortingDirection.Asc
}
});
}
Sorting は、IgbGridSortingStrategy アルゴリズムを使用して実行されます。IgbColumn または ISortingExpression は、代替アルゴリズムとして ISortingStrategy のカスタム実装を使用できます。たとえば複雑なテンプレート列や画像列にユーザー定義のソートを定義する必要がある場合に便利です。
フィルター動作と同様に、ソート状態をクリアするには ClearSort メソッドを使用します。
@code {
@*Removes the sorting state from the Title column*@
this.grid.ClearSortAsync("Title");
@*Removes the sorting state from every column in the Grid*@
this.grid.ClearSortAsync("");
}
IgbGrid.SortStrategy の SortStrategy は IgbColumn の SortStrategy と比較して異なるタイプです。異なるスコープで機能し、異なるパラメーターを公開するためです。
ソート操作で IgbGrid の基になるデータ ソースは変更しません。
初期のソート状態
IgbGrid でソート状態を初期設定するには、ソート式の配列を IgbGrid の SortingExpressions プロパティに渡します。
@code {
protected override void OnAfterRender(bool first)
{
if (first)
{
this.grid.SortingExpressions = new IgbSortingExpression[]{
new IgbSortingExpression()
{
FieldName = "Title",
Dir = SortingDirection.Asc
}};
}
}
}
リモート ソート
IgbGrid はリモート仮想化をサポートします。詳細については、Grid リモート データ操作で説明されています。
IgbGrid.SortHeaderIconTemplate– re-templates the sorting icon when no sorting is applied.
<IgbGrid SortHeaderIconTemplate="SortDefaultTemplate"></IgbGrid>
@code {
public RenderFragment<IgbGridHeaderTemplateContext> SortDefaultTemplate = (ctx) =>
{
return @<IgbIcon Size="SizableComponentSize.Small" IconName="unfold_more" Collection="material"></IgbIcon>;
};
}
IgbGrid.SortAscendingHeaderIconTemplate– re-templates the sorting icon when the column is sorted in ascending order.
<IgbGrid SortAscendingHeaderIconTemplate="SortAscendingTemplate"></IgbGrid>
@code {
public RenderFragment<IgbGridHeaderTemplateContext> SortAscendingTemplate = (ctx) =>
{
return @<IgbIcon Size="SizableComponentSize.Small" IconName="expand_less" Collection="material"></IgbIcon>;
};
}
IgbGrid.SortDescendingHeaderIconTemplate– re-templates the sorting icon when the column is sorted in descending order.
<IgbGrid SortDescendingHeaderIconTemplate="SortDescendingTemplate"></IgbGrid>
@code {
public RenderFragment<IgbGridHeaderTemplateContext> SortDescendingTemplate = (ctx) =>
{
return @<IgbIcon Size="SizableComponentSize.Small" IconName="expand_more" Collection="material"></IgbIcon>;
};
}
スタイル設定
ソート動作のスタイル設定は、すべてのテーマ関数とコンポーネント mixins が存在する index ファイルをインポートする必要があります。
<IgbGrid class="grid">
</IgbGrid>
最も簡単な方法は、grid-theme を拡張する新しいテーマを作成し、$sorted-header-icon-color、および sortable-header-icon-hover-color パラメーターを受け取る方法です。
@use "igniteui-angular/theming" as *;
// IMPORTANT: Prior to Ignite UI for Angular version 13 use:
// @import '~igniteui-angular/lib/core/styles/themes/index';
スタイル設定
API リファレンス
IgbGrid
IgbSortingExpression
Our community is active and always welcoming to new ideas.