Back to Devexpress

DxGrid.GetRowLevel(Int32) Method

blazor-devexpress-dot-blazor-dot-dxgrid-dot-getrowlevel-x28-system-dot-int32-x29.md

latest4.8 KB
Original Source

DxGrid.GetRowLevel(Int32) Method

Gets the nesting level of the processed row.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public int GetRowLevel(
    int visibleIndex
)

Parameters

NameTypeDescription
visibleIndexInt32

The row’s visible index.

|

Returns

TypeDescription
Int32

The row’s nesting level.

|

Remarks

The nesting level determines the number of group rows a user should expand to reach the processed row from the root. The root row’s level is 0, the level of its children is 1, and so on.

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 GetRowLevel method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.

The following code snippet gets the level of the row whose visible index is 2.

razor
@using Grid.Data
@inject WeatherForecastService ForecastService

<DxGrid Data="Data"
        ShowGroupPanel="true"
        @ref="MyGrid">
    <Columns>
        <DxGridDataColumn FieldName="Date"
                          DisplayFormat="D" />
        <DxGridDataColumn FieldName="TemperatureC"
                          GroupIndex="0" />
        <DxGridDataColumn FieldName="TemperatureF" />
        <DxGridDataColumn FieldName="Forecast" />
        <DxGridDataColumn FieldName="CloudCover"
                          GroupIndex="1" />
    </Columns>
</DxGrid>

<p />
<DxButton Click="OnGetRowLevel">Get the level of row 2</DxButton>
<p />
@Alert

@code {
    IGrid MyGrid { get; set; }
    object Data { get; set; }
    string Alert { get; set; }

    protected override void OnInitialized() {
        Data = ForecastService.GetForecast();
    }

    void OnGetRowLevel() {
        Alert = $"The level of row 2 is {MyGrid.GetRowLevel(2)}";
    }
}
csharp
using System;

public class WeatherForecast {
    public DateTime Date { get; set; }
    public int TemperatureC { get; set; }
    public double TemperatureF => Math.Round((TemperatureC * 1.8 + 32), 2);
    public string Forecast { get; set; }
    public string CloudCover { get; set; }
    public bool Precipitation { get; set; }
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

public class WeatherForecastService {
    private List<WeatherForecast> Forecast { get; set; }

    private static string[] CloudCover = new[] {
        "Sunny", "Partly cloudy", "Cloudy", "Storm"
    };

    Tuple<int, string>[] ConditionsForForecast = new Tuple<int, string>[] {
        Tuple.Create( 22 , "Hot"),
        Tuple.Create( 13 , "Warm"),
        Tuple.Create( 0 , "Cold"),
        Tuple.Create( -10 , "Freezing")
    };

    public WeatherForecastService() {
        Forecast = CreateForecast();
    }

    private List<WeatherForecast> CreateForecast() {
        var rng = new Random();
        DateTime startDate = DateTime.Now;
        return Enumerable.Range(1, 15).Select(index => {
            var temperatureC = rng.Next(-10, 30);
            return new WeatherForecast {
                Date = startDate.AddDays(index),               
                TemperatureC = temperatureC,
                CloudCover = CloudCover[rng.Next(0, 4)],
                Precipitation = Convert.ToBoolean(rng.Next(0, 2)),
                Forecast = ConditionsForForecast.First(c => c.Item1 <= temperatureC).Item2
            };
        }).ToList();
    }

    public IEnumerable<WeatherForecast> GetForecast() {
        return Forecast.ToArray();
        // ...
    }
csharp
// ...
builder.Services.AddSingleton<WeatherForecastService>();

Implements

GetRowLevel(Int32)

See Also

DxGrid Class

DxGrid Members

DevExpress.Blazor Namespace