DxGrid.GetDataItem(Int32) Method
Gets a data source item that is bound to the processed row.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
public object GetDataItem(
int visibleIndex
)
Parameters
Name | Type | Description |
---|---|---|
visibleIndex | Int32 | The row’s visible index. |
Returns
Type | Description |
---|---|
Object | The data item. |
Remarks
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:
- An Instant Feedback Data Source whose AreSourceRowsThreadSafe option is set to
false
(its default value) - A collection of anonymous objects
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.
Note
The Grid bound to an Instant Feedback Data Source or GridDevExtremeDataSource loads data asynchronously in small portions (instead of the entire dataset). Before you call the GetDataItem
method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.
The following code snippets perform these tasks:
- Obtain a data item bound to the row whose visible index is 3.
- Return the
Customer.City
field value for this item.
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
<DxGrid Data="GridDataSource"
CustomizeCellDisplayText="OnCustomizeCellDisplayText"
@ref="MyGrid">
<Columns>
<DxGridDataColumn FieldName="OrderDate"
DisplayFormat="d" />
<DxGridDataColumn FieldName="Customer"
SortMode="GridColumnSortMode.DisplayText" />
<DxGridDataColumn FieldName="Freight"
DisplayFormat="n2" />
</Columns>
</DxGrid>
<p />
<DxButton Click="OnGetDataItem">Get Data Item for Row 3</DxButton>
<p />
@Alert
@code {
IGrid MyGrid { get; set; }
object GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
public string Alert { get; set; } = "";
protected override void OnInitialized() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = Northwind.Orders
.Include(i => i.Customer)
.Include(i => i.OrderDetails)
.Include(i => i.ShipViaNavigation)
.ToList();
}
void OnCustomizeCellDisplayText(GridCustomizeCellDisplayTextEventArgs e) {
if (e.FieldName == "Customer") {
var customer = (Customer)e.Value;
e.DisplayText = $"{customer.CompanyName} ({customer.Country}, {customer.City})";
}
}
void OnGetDataItem() {
var dataItem = MyGrid.GetDataItem(3) as Grid.Northwind.Order;
Alert = $"The data item is obtained. The City field equals '{dataItem.Customer.City}'.";
}
public void Dispose() {
Northwind?.Dispose();
}
}