Skip to main content
A newer version of this page is available. .

DxGrid.GetDataItem(Int32) Method

Gets a data source item that is bound to the processed row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.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

The code below does the following:

  • Obtains a data item bound to the row whose visible index is 3.
  • Returns 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();
    }
}

Grid - Get Data Item

Note

When you use a GridDevExtremeDataSource, do not call the GetDataItem method for a row that is outside the visible display range. The GridDevExtremeDataSource loads only data required to display the current page.

Implements

See Also