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:
AttachNotifier, BlurNotifier<VirtualList<T>>, DetachNotifier, Focusable<VirtualList<T>>, FocusNotifier<VirtualList<T>>, HasElement, HasEnabled, HasSize, HasStyle, HasDataProvider<T>, HasItems<T>, Serializable

@Tag("vaadin-virtual-list") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.3.11") @NpmPackage(value="@vaadin/virtual-list",version="24.3.11") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/virtual-list/src/vaadin-virtual-list.js") @JsModule("./flow-component-renderer.js") @JsModule("./virtualListConnector.js") public class VirtualList<T> extends Component implements HasDataProvider<T>, HasStyle, HasSize, 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:
  • Constructor Details

    • VirtualList

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

    • setDataProvider

      public void setDataProvider(DataProvider<T,?> dataProvider)
      Description copied from interface: HasDataProvider
      Sets the data provider for this listing. The data provider is queried for displayed items as needed.
      Specified by:
      setDataProvider in interface HasDataProvider<T>
      Parameters:
      dataProvider - the data provider, not null
    • getDataProvider

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

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

      public void setRenderer(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)
      Description copied from class: Component
      Handle component enable state when the enabled state changes.

      By default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.

      Overrides:
      onEnabledStateChanged in class Component
      Parameters:
      enabled - the new enabled state of the 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.