blazor-devexpress-dot-blazor-dot-dxgrid-dot-makedataitemvisibleasync-x28-system-dot-object-x29.md
Makes the row bound to the specified data item visible on screen.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public Task MakeDataItemVisibleAsync(
object dataItem
)
| Name | Type | Description |
|---|---|---|
| dataItem | Object |
A data item.
|
| Type | Description |
|---|---|
| Task |
The task that is completed when the row becomes visible.
|
Pass a data item to the MakeDataItemVisibleAsync method to make the row bound to this data item visible on screen. Once called, the method performs the following actions:
The MakeDataItemVisibleAsync method makes no changes if the data item parameter refers to a row that is filtered out, not rendered yet, or does not exist.
The following code snippet navigates to the selected data row:
@using DxBlazorApplication.Data
@inject WeatherForecastService ForecastService
<DxButton Text="Go to the selected item" Click="ScrollToFirstSelectedItemAsync" />
<DxGrid @ref=Grid
Data="@forecasts"
AllowSelectRowByClick="true"
@bind-SelectedDataItem="@SelectedDataItem"
SelectionMode="GridSelectionMode.Single"
KeyFieldName="Date">
<Columns>
<DxGridDataColumn FieldName="Date" />
<DxGridDataColumn FieldName="TemperatureF" />
<DxGridDataColumn FieldName="Summary" GroupIndex="0"/>
</Columns>
</DxGrid>
@code {
IGrid Grid;
private WeatherForecast[]? forecasts;
object SelectedDataItem { get; set; }
async Task ScrollToFirstSelectedItemAsync() {
if(SelectedDataItem != null)
await Grid.MakeDataItemVisibleAsync(SelectedDataItem);
}
protected override async Task OnInitializedAsync() {
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
}
namespace DxBlazorApplication.Data {
public class WeatherForecast {
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}
namespace DxBlazorApplication.Data {
public class WeatherForecastService {
private static readonly string[] Summaries = new[] {
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate) {
var rng = new Random();
return Task.FromResult(Enumerable.Range(1, 20).Select(index => new WeatherForecast {
Date = startDate.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
}).ToArray());
}
}
}
// ...
builder.Services.AddSingleton<WeatherForecastService>();
MakeDataItemVisibleAsync(Object)
See Also
MakeCellVisible(Int32, String)