Back to Devexpress

DxGrid.GetVisibleRowCount() Method

blazor-devexpress-dot-blazor-dot-dxgrid-41147f22.md

latest5.3 KB
Original Source

DxGrid.GetVisibleRowCount() Method

Gets the total number of visible rows in the grid.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public int GetVisibleRowCount()

Returns

TypeDescription
Int32

The number of visible rows.

|

Remarks

The GetVisibleRowCount method returns the number of visible rows displayed in all grid pages. This number includes data rows and group rows (if data is grouped), but does not include filtered out rows and rows in collapsed groups. Refer to Row Visible Indexes for additional information.

razor
@using Grid.Data
@inject WeatherForecastService ForecastService

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

<p />
<DxButton Click="OnGetVisibleRowCount">Get Visible Row Count</DxButton>
<p />
@Alert

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

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

    void OnGetVisibleRowCount() {
        count = MyGrid.GetVisibleRowCount();
        Alert = "The visible row count equals " + count;
    }
}
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>();

For additional information about paging in the Grid component, refer to the following topic: Paging in Blazor Grid.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetVisibleRowCount() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

blazor-bunit-tests/CS/DevExpressBunit.Test/GridApplyFilter.cs#L22

csharp
cut.InvokeAsync(() => treeview.SelectNode(x => x.Text == "Filter by date"));
Assert.Equal(1, grid.GetVisibleRowCount());
cut.InvokeAsync(() => treeview.SelectNode(x => x.Text == "Filter by temperature"));

Implements

GetVisibleRowCount()

See Also

DxGrid Class

DxGrid Members

DevExpress.Blazor Namespace