Skip to content

Commit d19c41c

Browse files
committed
Virtualization updates
1 parent f1eb595 commit d19c41c

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

aspnetcore/blazor/components/virtualization.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,32 @@ The following example pins the viewport to the beginning of a virtualized flight
298298

299299
Modes can be combined. For example, assigning `Beginning | End` pins both edges. Combining `None` with other modes is supported but doesn't change the combined value.
300300

301-
`Virtualize.ItemComparer` gets or sets a comparer used to detect whether items were prepended or appended when using class-typed items with an <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.ItemsProvider%2A> (for more information, see the [Item provider delegate](#item-provider-delegate) section). The comparer determines if the first loaded item changed between provider calls, which indicates items were inserted at the top. For records, the default comparer's value-equality behavior (`EqualityComparer<T>.Default`) works automatically. For an in-memory <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.Items%2A> assignment, an `ItemComparer` comparer isn't required because the component can detect prepends automatically.
301+
`Virtualize.ItemComparer` gets or sets a comparer used to detect whether items were prepended or appended when using class-typed items with an <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.ItemsProvider%2A> (for more information, see the [Item provider delegate](#item-provider-delegate) section).
302+
303+
The comparer determines if the first loaded item changed between provider calls, which indicates items were inserted at the top. For records, the default comparer's value-equality behavior (`EqualityComparer<T>.Default`) works automatically. For an in-memory <xref:Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize%601.Items%2A> assignment, an `ItemComparer` comparer isn't required because the component can detect prepends automatically. In cases where non-primative objects are virtualized and the framework can't detect if an item is prepended or appended, assign an item comparer to the `Virtualize` component:
304+
305+
<!-- UPDATE 11.0 - Ilona ... Does the 'itemComparer' in the following example
306+
need the '@' symbol (ItemComparer="@itemComparer")?
307+
I thought that it wouldn't need it. -->
308+
309+
```razor
310+
<Virtualize ItemsProvider="LoadFlights" AnchorMode="Beginning"
311+
ItemComparer="itemComparer">
312+
...
313+
</Virtualize>
314+
315+
@code {
316+
private static readonly IEqualityComparer<DynamicItem> itemComparer =
317+
EqualityComparer<DynamicItem>.Create((a, b) =>
318+
a.Index == b.Index, item => item.Index);
319+
320+
private async ValueTask<ItemsProviderResult<Flight>> LoadFlights(
321+
ItemsProviderRequest request)
322+
{
323+
...
324+
}
325+
}
326+
```
302327

303328
:::moniker-end
304329

0 commit comments

Comments
 (0)