Completed
Last Updated: 22 Jul 2022 08:03 by ADMIN
Release 3.5.0
Viacheslav
Created on: 20 Jun 2022 12:02
Category: Grid
Type: Bug Report
1
Keyboard navigation allows going beyond the last page

Navigable="true" + OnRead data binding allow the user to go beyond the last Grid page. The component shows no rows, and even though the user can return to previous pages, it's cumbersome.

The workaround is to manage the Page value manually in the PageChanged handler.

@using Telerik.DataSource.Extensions

@*  workaround:  *@

@*Page="@GridPage"
PageChanged="@OnGridPageChanged"*@

<TelerikGrid OnRead="@OnGridRead"
             Navigable="true"
             TItem="@Product"
             Pageable="true">
    <GridColumns>
        <GridColumn Field="@nameof(Product.Name)" Title="Product Name" />
    </GridColumns>
</TelerikGrid>

@code {
    List<Product> GridData { get; set; }
    int GridPage { get; set; } = 1;
    int GridTotal { get; set; }

    // workaround
    void OnGridPageChanged(int newPage)
    {
        if (newPage > 0 && newPage <= Math.Ceiling((double)GridTotal / (double)10))
        {
            GridPage = newPage;
        }
    }

    void OnGridRead(GridReadEventArgs args)
    {
        var result = GridData.ToDataSourceResult(args.Request);

        args.Data = result.Data;
        args.Total = result.Total;

        // workaround
        //GridTotal = result.Total;
    }

    protected override void OnInitialized()
    {
        GridData = new List<Product>();
        var rnd = new Random();

        for (int i = 1; i <= 12; i++)
        {
            GridData.Add(new Product()
            {
                Id = i,
                Name = "Product " + i.ToString()
            });
        }
    }

    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

0 comments