Skip to content

Commit 1f03244

Browse files
SteveSandersonMSMackinnonBuck
authored andcommitted
Add OverscanCount parameter
1 parent f25896b commit 1f03244

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Components/Web/src/Virtualization/Virtualize.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ public sealed class Virtualize<TItem> : ComponentBase, IVirtualizeJsCallbacks, I
8888
[Parameter]
8989
public ICollection<TItem>? Items { get; set; }
9090

91+
/// <summary>
92+
/// Gets or sets a value that determines how many additional items will be rendered
93+
/// before and after the visible region. This help to reduce the frequency of rendering
94+
/// during scrolling. However, higher values mean that more elements will be present
95+
/// in the page.
96+
/// </summary>
97+
[Parameter]
98+
public int OverscanCount { get; set; } = 3;
99+
91100
/// <inheritdoc />
92101
protected override void OnParametersSet()
93102
{
@@ -251,8 +260,8 @@ private void CalcualteItemDistribution(
251260
_itemSize = ItemSize;
252261
}
253262

254-
itemsInSpacer = Math.Max(0, (int)Math.Floor(spacerSize / _itemSize) - 1);
255-
visibleItemCapacity = (int)Math.Ceiling(containerSize / _itemSize) + 2;
263+
itemsInSpacer = Math.Max(0, (int)Math.Floor(spacerSize / _itemSize) - OverscanCount);
264+
visibleItemCapacity = (int)Math.Ceiling(containerSize / _itemSize) + 2 * OverscanCount;
256265
}
257266

258267
private void UpdateItemDistribution(int itemsBefore, int visibleItemCapacity)

0 commit comments

Comments
 (0)