From ba42313c5fed7ddb73acaa92377757a63426b8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Mon, 12 Aug 2024 16:58:36 +0200 Subject: [PATCH] Fix near page indexes crashing on invalid page number ... which can very plausibly occur when rows get removed fixes #1835 --- src/Framework/Core/Controls/Options/PagingOptions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Framework/Core/Controls/Options/PagingOptions.cs b/src/Framework/Core/Controls/Options/PagingOptions.cs index 9a626f53fe..83e009520e 100644 --- a/src/Framework/Core/Controls/Options/PagingOptions.cs +++ b/src/Framework/Core/Controls/Options/PagingOptions.cs @@ -107,8 +107,10 @@ public virtual IList GetNearPageIndexes() /// protected virtual IList GetDefaultNearPageIndexes(int distance) { - var firstIndex = Math.Max(PageIndex - distance, 0); - var lastIndex = Math.Min(PageIndex + distance + 1, PagesCount); + var count = this.PagesCount; + var index = Math.Max(0, Math.Min(count - 1, 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) .ToList();