blazor-devexpress-dot-blazor-dot-dxgrid-f30031d3.md
Returns a data item bound to the focused data row.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public object GetFocusedDataItem()
| Type | Description |
|---|---|
| Object |
If a data row is focused, the method returns the data item bound to this row. The method returns null if a group or new row is focused or the Grid displays no rows.
|
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:
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 additional information about row focus in the Grid component, refer to the following topic: Selection and Focus in Blazor Grid.
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:
false (its default value)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();
}
}
See Also