From 867508da498f34dc789444510805df2ce2ab6330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Mon, 12 Aug 2024 16:56:15 +0200 Subject: [PATCH] Fix near page indexes crashing on invalid page number ... which can very plausibly occur when rows get removed fixes #1835 --- .../Controls/Options/DistanceNearPageIndexesProvider.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Framework/Core/Controls/Options/DistanceNearPageIndexesProvider.cs b/src/Framework/Core/Controls/Options/DistanceNearPageIndexesProvider.cs index f40ac13687..79cdec24d9 100644 --- a/src/Framework/Core/Controls/Options/DistanceNearPageIndexesProvider.cs +++ b/src/Framework/Core/Controls/Options/DistanceNearPageIndexesProvider.cs @@ -26,8 +26,10 @@ public DistanceNearPageIndexesProvider(int distance) /// The settings for paging. public IList GetIndexes(IPagingOptions pagingOptions) { - var firstIndex = Math.Max(pagingOptions.PageIndex - distance, 0); - var lastIndex = Math.Min(pagingOptions.PageIndex + distance + 1, pagingOptions.PagesCount); + var count = pagingOptions.PagesCount; + var index = Math.Max(0, Math.Min(count - 1, pagingOptions.PageIndex)); // clamp index to be a valid page + var firstIndex = Math.Max(index - distance, 0); + var lastIndex = Math.Min(index + distance + 1, count); return Enumerable .Range(firstIndex, lastIndex - firstIndex)