Skip to main content

DxGrid.GetFocusedDataItem() Method

Returns a data item bound to the focused data row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public object GetFocusedDataItem()

Returns

Type Description
Object

A data item; null for a group row or if the Grid has no data to display.

Remarks

When the FocusedRowEnabled property is set to true, the grid displays the focused row. Call the GetFocusedDataItem method to get the data item bound to the focused data row. This method returns null in the following cases:

  • The currently focused row is a group row
  • The Grid has no data to display (for instance, when the applied filter has no matching data or data is not loaded to the grid)

To focus a row bound to the specified data item, call the SetFocusedDataItemAsync(Object) method. When the focused row changes, the grid raises the FocusedRowChanged event. For more information about row focus in the Grid component, refer to the following topic: Selection and Focus in Blazor Grid.

Obtain Item Field Values

Pass a data item to the GetDataItemValue method to get the item’s field value when the Grid is bound to one of the following data sources:

In other cases, you can cast a data item to the corresponding type and use the {DataItem.FieldName} notation to get the item’s field value.

In the following code sample, the GetFocusedDataItem method is used to get additional information about the focused employee.

<DxGrid @ref="Grid" Id="grid" Data="GridData" PageSize="5" FocusedRowEnabled="true">
    <Columns>
        <DxGridDataColumn FieldName="FirstName" />
        <DxGridDataColumn FieldName="LastName" />
        <DxGridDataColumn FieldName="Title" />
        <DxGridDataColumn FieldName="HireDate" />
    </Columns>
</DxGrid>
<DxButton Text="Show Details" Click="ShowDetails"></DxButton>
<DxDropDown HeaderVisible="true" HeaderText="@MemoCaption" BodyText="@Notes" @bind-IsOpen=IsOpen 
            PositionMode="DropDownPositionMode.Center"  Width="500px" PositionTarget="#grid" />
@code {
    IGrid Grid { get; set; }
    string MemoCaption { get; set; }
    string Notes { get; set; }
    bool IsOpen { get; set; } = false;
    void ShowDetails(MouseEventArgs e) {
        if(Grid.GetFocusedDataItem() != null) {
            var employee = (Employee)Grid.GetFocusedDataItem();
            MemoCaption = employee.FirstName + " " + employee.LastName + " details:";
            Notes = employee.Notes;
            IsOpen = !IsOpen;
        }
    }
    object GridData { get; set; }
    protected override async Task OnInitializedAsync() {
        GridData = await NwindDataService.GetEmployeesAsync();
    }
}

Grid Focused Row

See Also