Back to Devexpress

DxGrid.MakeDataItemVisibleAsync(Object) Method

blazor-devexpress-dot-blazor-dot-dxgrid-dot-makedataitemvisibleasync-x28-system-dot-object-x29.md

latest4.5 KB
Original Source

DxGrid.MakeDataItemVisibleAsync(Object) Method

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

Declaration

csharp
public Task MakeDataItemVisibleAsync(
    object dataItem
)

Parameters

NameTypeDescription
dataItemObject

A data item.

|

Returns

TypeDescription
Task

The task that is completed when the row becomes visible.

|

Remarks

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:

  1. If the row is in a collapsed group, expands the group.
  2. If the row is on another page, navigates to that page and updates the PageIndex property.
  3. Scrolls the Grid up or down until the row appears.

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:

razor
@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);
    }
}
csharp
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; }
    }
}
csharp
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());
        }
    }
}
csharp
// ...
builder.Services.AddSingleton<WeatherForecastService>();

Implements

MakeDataItemVisibleAsync(Object)

See Also

MakeCellVisible(Int32, String)

MakeCellVisibleAsync(Object, String)

MakeRowVisible(Int32)

DxGrid Class

DxGrid Members

DevExpress.Blazor Namespace