IgbGrid でフォーカスが当たっているアクティブなセルに紐づいたデータを取得したい場合は、アクティブなノードが変わったときに発生する ActiveNodeChange イベントコールバックを使ってアクティブセルの行インデックスを取得し、それをもとに紐づいているデータを取得します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<IgbGrid @ref="grid"
Data="People" PrimaryKey="ID" ...
ActiveNodeChange="OnActiveNodeChange" ... >
...
</IgbGrid>
@code {
private IEnumerable<Person>? People = null;
private Person? PersonOfActiveCell = null;
private IgbGrid? grid;
private async Task OnActiveNodeChange(IgbActiveNodeChangeEventArgs e)
{
if(this.grid != null)
{
// アクティブセルの行インデックスを取得する。
int activeRowIndex = (int)e.Detail.Row;
// 行インデックスをもとにRowTypeオブジェクトを取得する。
var rowType = await this.grid.GetRowByIndexAsync(activeRowIndex);
// 紐づいているデータを取り出す。
this.PersonOfActiveCell = rowType.Data as Person;
}
}
}
<IgbGrid @ref="grid" Data="People" PrimaryKey="ID" ... ActiveNodeChange="OnActiveNodeChange" ... > ... </IgbGrid> @code { private IEnumerable<Person>? People = null; private Person? PersonOfActiveCell = null; private IgbGrid? grid; private async Task OnActiveNodeChange(IgbActiveNodeChangeEventArgs e) { if(this.grid != null) { // アクティブセルの行インデックスを取得する。 int activeRowIndex = (int)e.Detail.Row; // 行インデックスをもとにRowTypeオブジェクトを取得する。 var rowType = await this.grid.GetRowByIndexAsync(activeRowIndex); // 紐づいているデータを取り出す。 this.PersonOfActiveCell = rowType.Data as Person; } } }
<IgbGrid @ref="grid"
    Data="People" PrimaryKey="ID" ...
    ActiveNodeChange="OnActiveNodeChange" ... >
    ...
</IgbGrid>

@code {
    private IEnumerable<Person>? People = null;
    private Person? PersonOfActiveCell = null;
    private IgbGrid? grid;

    private async Task OnActiveNodeChange(IgbActiveNodeChangeEventArgs e)
    {
        if(this.grid != null)
        {
            // アクティブセルの行インデックスを取得する。
            int activeRowIndex = (int)e.Detail.Row;
            // 行インデックスをもとにRowTypeオブジェクトを取得する。
            var rowType = await this.grid.GetRowByIndexAsync(activeRowIndex);
            // 紐づいているデータを取り出す。
            this.PersonOfActiveCell = rowType.Data as Person;
        }
    }
}

 

実行結果

 

 

Tagged:

製品について

Ignite UI for Blazor