Class VirtualList<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.virtuallist.VirtualList<T>
Type Parameters:
T - the type of the items supported by the list
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<VirtualList<T>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<VirtualList<T>>, com.vaadin.flow.component.FocusNotifier<VirtualList<T>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.data.binder.HasDataProvider<T>, com.vaadin.flow.data.binder.HasItems<T>, Serializable

@Tag("vaadin-virtual-list") @NpmPackage(value="@vaadin/virtual-list", version="25.0.0-alpha17") @JsModule("@vaadin/virtual-list/src/vaadin-virtual-list.js") @JsModule("./flow-component-renderer.js") @JsModule("./virtualListConnector.js") public class VirtualList<T> extends com.vaadin.flow.component.Component implements com.vaadin.flow.data.binder.HasDataProvider<T>, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.Focusable<VirtualList<T>>
Virtual List allows you to render a long list of items inside a scrollable container without sacrificing performance. Each item is rendered on the fly as the user scrolls the list. To use the component, you need to assign it a set of data items and a renderer that is used for rendering each individual data item. The height of an item is determined by its content and can change dynamically.

This component supports DataProviders to load data asynchronously and Renderers to render the markup for each item.

Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty list.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.data.provider.DataCommunicator<T>
    Returns the data communicator of this list.
    com.vaadin.flow.data.provider.DataProvider<T,?>
    Returns the data provider of this list.
    com.vaadin.flow.function.SerializableFunction<T,String>
    Gets the function that generates accessible names for virtual list items.
    Gets the placeholder item of this list, or null if none has been set.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    onEnabledStateChanged(boolean enabled)
     
    void
    Scrolls to the last element of the list.
    void
    scrollToIndex(int rowIndex)
    Scrolls to the given row index.
    void
    Scrolls to the first element.
    void
    setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,?> dataProvider)
     
    void
    setItemAccessibleNameGenerator(com.vaadin.flow.function.SerializableFunction<T,String> itemAccessibleNameGenerator)
    A function that generates accessible names for virtual list items.
    void
    setPlaceholderItem(T placeholderItem)
    Sets an item to be shown as placeholder in the list while the real data in being fetched from the server.
    void
    setRenderer(Renderer<T> renderer)
    Sets a renderer for the items in the list.
    void
    setRenderer(com.vaadin.flow.function.ValueProvider<T,String> valueProvider)
    Sets a renderer for the items in the list, by using a ValueProvider.

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.data.binder.HasDataProvider

    setItems

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.data.binder.HasItems

    setItems, setItems

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
  • Constructor Details

    • VirtualList

      public VirtualList()
      Creates an empty list.
  • Method Details

    • setDataProvider

      public void setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,?> dataProvider)
      Specified by:
      setDataProvider in interface com.vaadin.flow.data.binder.HasDataProvider<T>
    • getDataProvider

      public com.vaadin.flow.data.provider.DataProvider<T,?> getDataProvider()
      Returns the data provider of this list.
      Returns:
      the data provider of this list, not null
    • getDataCommunicator

      public com.vaadin.flow.data.provider.DataCommunicator<T> getDataCommunicator()
      Returns the data communicator of this list.
      Returns:
      the data communicator, not null
    • setRenderer

      public void setRenderer(com.vaadin.flow.function.ValueProvider<T,String> valueProvider)
      Sets a renderer for the items in the list, by using a ValueProvider. The String returned by the provider is used to render each item.
      Parameters:
      valueProvider - a provider for the label string for each item in the list, not null
    • setRenderer

      public void setRenderer(Renderer<T> renderer)
      Sets a renderer for the items in the list.

      When set, a same renderer is used for the placeholder item. See setPlaceholderItem(Object) for details.

      Parameters:
      renderer - a renderer for the items in the list, not null
    • setPlaceholderItem

      public void setPlaceholderItem(T placeholderItem)
      Sets an item to be shown as placeholder in the list while the real data in being fetched from the server.

      Setting a placeholder item improves the user experience of the list while scrolling, since the placeholder uses the same renderer set with setRenderer(Renderer), maintaining the same height for placeholders and actual items.

      When no placeholder item is set (or when set to null), an empty placeholder element is created.

      Note: when using ComponentRenderers, the component used for the placeholder is statically stamped in the list. It can not be modified, nor receives any events.

      Parameters:
      placeholderItem - the item used as placeholder in the list, while the real data is being fetched from the server
    • getPlaceholderItem

      public T getPlaceholderItem()
      Gets the placeholder item of this list, or null if none has been set.
      Returns:
      the placeholder item
    • onEnabledStateChanged

      public void onEnabledStateChanged(boolean enabled)
      Overrides:
      onEnabledStateChanged in class com.vaadin.flow.component.Component
    • scrollToIndex

      public void scrollToIndex(int rowIndex)
      Scrolls to the given row index. Scrolls so that the element is shown at the start of the visible area whenever possible.

      If the index parameter exceeds current item set size the grid will scroll to the end.

      Parameters:
      rowIndex - zero based index of the item to scroll to in the current view.
    • scrollToStart

      public void scrollToStart()
      Scrolls to the first element.
    • scrollToEnd

      public void scrollToEnd()
      Scrolls to the last element of the list.
    • setItemAccessibleNameGenerator

      public void setItemAccessibleNameGenerator(com.vaadin.flow.function.SerializableFunction<T,String> itemAccessibleNameGenerator)
      A function that generates accessible names for virtual list items. The function gets the item as an argument and the return value should be a string representing that item. The result gets applied to the corresponding virtual list child element as an `aria-label` attribute.
      Parameters:
      itemAccessibleNameGenerator - the item accessible name generator to set, not null
      Throws:
      NullPointerException - if itemAccessibleNameGenerator is null
    • getItemAccessibleNameGenerator

      public com.vaadin.flow.function.SerializableFunction<T,String> getItemAccessibleNameGenerator()
      Gets the function that generates accessible names for virtual list items.
      Returns:
      the item accessible name generator
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component