Class 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
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
BlurNotifier.BlurEvent<C extends Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the data communicator of this list.DataProvider<T,?> Returns the data provider of this list.Gets the function that generates accessible names for virtual list items.Gets the placeholder item of this list, ornullif none has been set.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidonEnabledStateChanged(boolean enabled) Handle component enable state when the enabled state changes.voidScrolls to the last element of the list.voidscrollToIndex(int rowIndex) Scrolls to the given row index.voidScrolls to the first element.voidsetDataProvider(DataProvider<T, ?> dataProvider) Sets the data provider for this listing.voidsetItemAccessibleNameGenerator(SerializableFunction<T, String> itemAccessibleNameGenerator) A function that generates accessible names for virtual list items.voidsetPlaceholderItem(T placeholderItem) Sets an item to be shown as placeholder in the list while the real data in being fetched from the server.voidsetRenderer(Renderer<T> renderer) Sets a renderer for the items in the list.voidsetRenderer(ValueProvider<T, String> valueProvider) Sets a renderer for the items in the list, by using aValueProvider.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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.data.binder.HasDataProvider
setItemsMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods 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, setWidthFullMethods 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
Description copied from interface:HasDataProviderSets the data provider for this listing. The data provider is queried for displayed items as needed.- Specified by:
setDataProviderin interfaceHasDataProvider<T>- Parameters:
dataProvider- the data provider, not null
-
getDataProvider
Returns the data provider of this list.- Returns:
- the data provider of this list, not
null
-
getDataCommunicator
Returns the data communicator of this list.- Returns:
- the data communicator, not
null
-
setRenderer
Sets a renderer for the items in the list, by using aValueProvider. 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, notnull
-
setRenderer
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, notnull
-
setPlaceholderItem
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
Gets the placeholder item of this list, ornullif none has been set.- Returns:
- the placeholder item
-
onEnabledStateChanged
public void onEnabledStateChanged(boolean enabled) Description copied from class:ComponentHandle 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:
onEnabledStateChangedin classComponent- 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. -
setItemAccessibleNameGenerator
public void setItemAccessibleNameGenerator(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, notnull- Throws:
NullPointerException- ifitemAccessibleNameGeneratorisnull
-
getItemAccessibleNameGenerator
Gets the function that generates accessible names for virtual list items.- Returns:
- the item accessible name generator
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method.
-