riganti / dotvvm

Open source MVVM framework for Web Apps
https://www.dotvvm.com
Apache License 2.0
743 stars 97 forks source link

GridViewDataSet PagingOptions NearPageIndexes error, version Dotvvm 4.2.7 #1835

Closed tengulak closed 1 month ago

tengulak commented 2 months ago

I think there is a very old bug in PagingOptions in NearPageIndexes calculation class DistanceNearPageIndexesProvider function GetIndexes.

I have a page with bs:GridView and GridViewDataSet, TotalItemsCount = 235, PagesCount = 12 PageSize = 20 Go to page number 12 through (bs:DataPager) Change PageSize to = 200 and exception out of range fired in function GetIndexes

In short story if PageIndex>PagesCount then lastIndex < firstIndex a Enumerable.Range fires an exception !! So i suggest a fix to this function and add following line of code at beginning

if (pagingOptions.PageIndex > pagingOptions.PagesCount) pagingOptions.PageIndex = pagingOptions.PagesCount - 1;

By the way, your blog on www.riganti.cz/ still getting first page, another bug of paging.

public IList<int> GetIndexes(IPagingOptions pagingOptions)
{
    var firstIndex = Math.Max(pagingOptions.PageIndex - distance, 0);
    var lastIndex = Math.Min(pagingOptions.PageIndex + distance + 1, pagingOptions.PagesCount);

    return Enumerable              //over here an exception !!!!!!!
        .Range(firstIndex, lastIndex - firstIndex)
        .ToList();
}