Skip to content

VirtualList

A high-performance scrollable list that only renders visible items. Designed for large datasets where a full Grid would be excessive.

VirtualList.builder()
.page(new Page<>("", 20, 1, items.size(), items.stream()
.map(i -> (Component) new Text(i.getName()))
.toList()))
.build()
PropertyTypeDefaultDescription
pagePage<Component>The current page of rendered components
styleStringInline CSS — set a fixed height for virtual scrolling
cssClassesStringCSS class names

Each item in the page is a Component — you control exactly how each row looks.

new Page<>(
sortProperty, // String
pageSize, // int
pageNumber, // int (1-based)
totalItems, // int
List<Component> // rendered rows
)
List<Component> rows = products.stream()
.map(p -> HorizontalLayout.builder()
.spacing(true)
.content(List.of(
new Image(p.getImageUrl()),
new Text(p.getName()),
new Badge("" + p.getPrice())
))
.build())
.map(Component.class::cast)
.toList();
VirtualList.builder()
.page(new Page<>("", 20, 1, products.size(), rows))
.style("height: 500px;")
.build()

Always set an explicit height on the VirtualList container so the browser knows when to start virtualising.