Skip to main content
All docs
V26.1
  • DxGrid.GetPageCount() Method

    Returns the total number of pages in the Grid.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.Grid.v26.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public int GetPageCount()

    Returns

    Type Description
    Int32

    The total number of pages.

    Remarks

    The Grid automatically calculates the number of pages required to show all rows. The PageSize property specifies the maximum number of rows displayed on a page. User can change the page size at runtime if you display the page size selector. The page count also changes when you group/ungroup or filter data.

    Call the GetPageCount method to get the total number of Grid pages.

    The following example determines the number of pages in the Grid, then navigates to the last page. These actions take place when the Grid renders itself for the first time.

    @using Microsoft.EntityFrameworkCore
    @inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
    @implements IDisposable
    
    <DxGrid Data="@Data"
            @bind-PageIndex="@PageIndex"
            @ref="MyGrid">
        <Columns>
            <DxGridDataColumn FieldName="ShipName" />
            <DxGridDataColumn FieldName="ShipCity" />
            <DxGridDataColumn FieldName="ShipCountry" />
            <DxGridDataColumn FieldName="Freight" />
            <DxGridDataColumn FieldName="OrderDate" />
            <DxGridDataColumn FieldName="ShippedDate" />
        </Columns>
    </DxGrid>
    
    @code {
        object Data { get; set; }
        NorthwindContext Northwind { get; set; }
        IGrid MyGrid { get; set; }
        int PageIndex { get; set; }
    
        protected override void OnInitialized() {
            Northwind = NorthwindContextFactory.CreateDbContext();
            Data = Northwind.Orders.ToList();
        }
    
        protected override void OnAfterRender(bool firstRender) {
            if (firstRender) {
                PageIndex = MyGrid.GetPageCount() - 1;
                StateHasChanged();
            }
        }
    
        public void Dispose() {
            Northwind?.Dispose();
        }
    }
    

    Blazor Grid Page Count

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

    Implements

    See Also