com.vaadin.flow.component.grid.
Class Grid<T>
Type Parameters:
T
- the grid bean type
All Implemented Interfaces:
AttachNotifier
, BlurNotifier<Grid<T>>
, DetachNotifier
, Focusable<Grid<T>>
, FocusNotifier<Grid<T>>
, HasElement
, HasEnabled
, HasSize
, HasStyle
, HasTheme
, SortEvent.SortNotifier<Grid<T>,
, HasDataGenerators<T>
, HasDataView<T,
, HasLazyDataView<T,
, HasListDataView<T,
, Serializable
Grid is a component for showing tabular data. A basic Grid uses plain text to display information in rows and columns. However, rich content can be used to provide additional information in a more legible fashion using component renderers or Lit renderers. The Grid supports the following features.
Dynamic Height:
Grid has a default height of 400 pixels. It becomes scrollable when its items
overflow the allocated space. In addition to setting any fixed or relative
value, the height of a grid can be set by the number of items in the dataset,
meaning that the grid will grow and shrink based on the row count.
Selection:
Grid selection is not enabled by default. Grid supports single and
multi-select. The former allows the user to select exactly one item while the
latter enables multiple items to be selected. In single selection mode, the
user can select and deselect rows by clicking anywhere on the row. In
multi-select mode, the user can use a checkbox column to select and deselect
rows.
Columns:
Column alignment, freezing (fixed position), grouping, headers & footers,
visibility, and width can be configured. Users can be allowed to resize and
reorder columns.
Sorting:
Any column can be made sortable. Enable sorting to allow the user to sort
items alphabetically, numerically, by date, etc. You can also sort columns
that contain rich and/or custom content by defining which property to sort
by. For example, you can have a column containing a person?s profile picture,
name and email sorted by the person?s last name. Sorting helps users find and
analyze the data, so it?s generally recommended to enable it for all
applicable columns, except in cases where the order of items is an essential
part of the data itself (such as prioritized lists).
Filtering:
Filtering allows the user to quickly find a specific item or subset of items.
You can add filters to Grid columns or use external filter fields.
Item Details:
Item Details are expandable content areas that can be displayed below the
regular content of a row, used to display more information about an item. By
default, an item?s details are toggled by clicking on the item?s row. The
default toggle behavior can be replaced by programmatically toggling the
details visibility, for example, from a button click.
Context Menu:
You can use Context Menu to provide shortcuts to the user. It appears on
right (default) or left click. In a mobile browser, a long press opens the
menu.
Drag and Drop:
Grid supports drag and drop, for example to reorder rows and to drag rows
between grids.
Inline Editing:
Grid can be configured to allow inline editing. Editing can be either
buffered and non-buffered. Buffered means changes must be explicitly
committed, while non-buffered automatically commit changes on blur (when a
field loses focus).
Styling Rows and Columns:
You can style individual cells based on the data, for example, to highlight
changes or important information.
Cell Focus:
Cells can be focused by clicking on a cell or with the keyboard.
Author:
Vaadin Ltd
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A helper base class for creating extensions for the Grid component.
static class
Server-side component for the
<vaadin-grid-column>
element.protected static class
Grid.DataCommunicatorBuilder<T,
U extends ArrayUpdater> Builder for
DataCommunicator
object.static enum
Multi-sort priority (visually indicated by numbers in column headers) controls how columns are added to the sort order, when a column becomes sorted, or the sort direction of a column is changed.
static enum
behavior when parsing nested properties which may contain
null
values in the property chainstatic enum
Selection mode representing the built-in selection models in grid.
static interface
protected static class
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
ConstructorsModifierConstructorDescriptionGrid()
Creates a new instance, with page size of 50.
Grid
(int pageSize) Creates a new instance, with the specified page size.
protected
Grid
(int pageSize, SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueBuilder, B dataCommunicatorBuilder) Creates a new instance, with the specified page size and data communicator.
Grid
(BackEndDataProvider<T, Void> dataProvider) Creates a new grid using the given
BackEndDataProvider
.Grid
(DataProvider<T, Void> dataProvider) Creates a new grid using the given generic
DataProvider
.Grid
(InMemoryDataProvider<T> inMemoryDataProvider) Creates a new grid using the given
InMemoryDataProvider
.Grid
(ListDataProvider<T> dataProvider) Creates a new grid using the given
ListDataProvider
.Creates a new grid with an initial set of columns for each of the bean's properties.
Creates a new grid with an initial set of columns for each of the bean's properties.
protected
Grid
(Class<T> beanType, SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueBuilder, B dataCommunicatorBuilder) Creates a new grid with an initial set of columns for each of the bean's properties.
protected
Grid
(Class<T> beanType, SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueBuilder, B dataCommunicatorBuilder, boolean autoCreateColumns) Creates a new grid with an initial set of columns for each of the bean's properties.
Grid
(Collection<T> items) Creates a new grid using the given collection of items using a
ListDataProvider
. -
Method Summary
Modifier and TypeMethodDescriptionaddCellFocusListener
(ComponentEventListener<CellFocusEvent<T>> listener) Adds a listener to the grid that will be notified, when a cell has been focused.
Adds a new text column to this
Grid
with a renderer and default column factory.protected <C extends Grid.Column<T>>
CAdds a new text column to this
Grid
with a renderer and column factory provided.addColumn
(ValueProvider<T, ?> valueProvider) Adds a new text column to this
Grid
with a value provider and default column factory.protected <C extends Grid.Column<T>>
CaddColumn
(ValueProvider<T, ?> valueProvider, BiFunction<Renderer<T>, String, C> columnFactory) Adds a new text column to this
Grid
with a value provider and column factory provided.<V extends Comparable<? super V>>
Grid.Column<T>addColumn
(ValueProvider<T, V> valueProvider, String... sortingProperties) Adds a new text column to this
Grid
with a value provider and sorting properties.The value is converted to a JSON value by usingJsonSerializer.toJson(Object)
.Adds a new column for the given property name with the default column factory.
protected <C extends Grid.Column<T>>
CAdds a new column for the given property name with the column factory provided.
Adds a column reorder listener to this component.
Adds a column resize listener to this component.
void
addColumns
(String... propertyNames) Adds a new columns for the given property names.
<V extends Component>
Grid.Column<T>addComponentColumn
(ValueProvider<T, V> componentProvider) Adds a new column that shows components.
Adds a new context-menu for this grid.
addDataGenerator
(DataGenerator<T> dataGenerator) Adds the given data generator.
addDragEndListener
(ComponentEventListener<GridDragEndEvent<T>> listener) Adds a drag end listener to this component.
Adds a drag start listener to this component.
addDropListener
(ComponentEventListener<GridDropEvent<T>> listener) Adds a drop listener to this component.
protected HeaderRow
addItemClickListener
(ComponentEventListener<ItemClickEvent<T>> listener) Adds an item click listener to this component.
Adds an item double click listener to this component.
addSelectionListener
(SelectionListener<Grid<T>, T> listener) Adds a selection listener to the current selection model.
addSortListener
(ComponentEventListener<SortEvent<Grid<T>, GridSortOrder<T>>> listener) Adds a sort order change listener that gets notified when the sort order changes.
void
addThemeVariants
(GridVariant... variants) Adds theme variants to the component.
addValueProvider
(String property, ValueProvider<T, ?> valueProvider) Adds a ValueProvider to this Grid that is not tied to a Column.
Adds a new footer row to the bottom of the existing footer rows.
Adds a new header row to the bottom of the existing header rows.
MultiSelect<Grid<T>,
T> Use this grid as a multiselect in
Binder
.SingleSelect<Grid<T>,
T> Use this grid as a single select in
Binder
.protected static int
void
configureBeanType
(Class<T> beanType, boolean autoCreateColumns) Sets the bean type this grid is bound to and optionally adds a set of columns for each of the bean's properties.
protected Grid.Column<T>
createColumn
(Renderer<T> renderer, String columnId) Deprecated.
This method should not be used outside.protected String
createColumnId
(boolean increment) protected GridArrayUpdater
createDefaultArrayUpdater
(SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueFactory) Creates a new Editor instance.
protected SerializableComparator<T>
Creates a comparator for grid to sort rows.
void
This method is a shorthand that delegates to the currently set selection model.
void
This method is a shorthand that delegates to the currently set selection model.
Gets the aria-label of the component.
protected GridArrayUpdater
Returns the Class of bean this Grid is constructed with via
Grid(Class)
.Gets the function that is used for generating CSS class names for rows in this grid.
getColumnByKey
(String columnKey) Gets a
Grid.Column
of this grid by its key.protected List<com.vaadin.flow.component.grid.ColumnLayer>
Gets the current column rendering mode.
List<Grid.Column<T>>
Gets an unmodifiable list of all
Grid.Column
s currently in thisGrid
.Returns the data communicator of this Grid.
DataProvider<T,
?> Returns the data provider of this grid.
protected BiFunction<Renderer<T>,
String, Grid.Column<T>> Gives a reference to the column factory.
protected HeaderRow
Gets the active drag filter.
Gets the active drop filter.
Gets the drop mode of this drop target.
Gets the editor.
Returns the component that is displayed when the grid is empty.
Returns the text that is displayed when the grid is empty.
Gets all of the footer rows in the Grid, in order from top to bottom.
Gets the generic data view for the grid.
Gets all of the header rows in the Grid, in order from top to bottom.
Gets the lazy data view for the grid.
Gets the list data view for the grid.
Get the behavior when facing nested
null
values.int
Gets the current page size, which is the number of items fetched at a time from the dataprovider.
Gets the function that is used for generating CSS part names for rows in this grid.
Returns
PropertySet
of bean this Grid is constructed with viaGrid(Class)
.This method is a shorthand that delegates to the currently set selection model.
Returns the selection mode for this grid.
Returns the selection model for this grid.
Gets the selection preservation mode.
Gets an list of the current sort orders in the Grid.
Gets the tooltip position relative to the cell that is being hovered or focused.
protected String
Gets property name for unique key in row's generated JSON.
protected ValueProvider<T,
String> Gets optional value provider for unique key in row's generated JSON.
protected void
protected com.vaadin.flow.component.grid.ColumnLayer
insertColumnLayer
(int index, List<com.vaadin.flow.component.grid.AbstractColumn<?>> columns) Creates a new layer from the provided columns, inserts the layer into given index and returns the new layer.
boolean
Gets whether grid's height is defined by the number of its rows.
boolean
Returns whether column reordering is allowed.
boolean
isDetailsVisible
(T item) Returns the visibility of details component for given item.
boolean
Gets whether the item details are opened and closed by clicking the rows or not.
boolean
Gets whether multiple column sorting is enabled on the client-side.
boolean
Gets whether rows of the grid can be dragged.
protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.
protected void
Callback which is called if a new data provider is set or any change happen in the current data provider (an
DataChangeEvent
event is fired).protected void
onDetach
(DetachEvent detachEvent) Called when the component is detached from a UI.
void
onEnabledStateChanged
(boolean enabled) Handle component enable state when the enabled state changes.
Adds a new footer row on the top of the existing footer rows.
Adds a new header row on the top of the existing header rows.
void
Updates the
width
of all columns which haveautoWidth
set totrue
.void
Removes all columns from this Grid.
void
Removes all footer rows from the grid.
void
Removes all header rows from the grid.
void
removeColumn
(Grid.Column<T> column) Removes a column from the Grid.
void
removeColumnByKey
(String columnKey) Removes a column with the given column key from the Grid.
protected void
removeColumnLayer
(com.vaadin.flow.component.grid.ColumnLayer layer) Removes the given layer and moves the columns on the lower level to its place.
void
removeColumns
(Grid.Column<T>... columns) Removes columns from the Grid.
void
removeFooterRow
(FooterRow footerRow) Removes the footer row from the grid.
void
removeHeaderRow
(HeaderRow headerRow) Removes the header row from the grid.
void
removeThemeVariants
(GridVariant... variants) Removes theme variants from the component.
void
Scrolls to the last data row of the grid.
void
scrollToIndex
(int rowIndex) Scrolls to the given row index.
void
scrollToItem
(T item) Scrolls to the row presenting the given item.
void
Scrolls to the beginning of the first data row.
void
This method is a shorthand that delegates to the currently set selection model.
void
setAllRowsVisible
(boolean allRowsVisible) If
true
, the grid's height is defined by its rows.void
setAriaLabel
(String ariaLabel) Set the aria-label of the component to the given text.
void
setClassNameGenerator
(SerializableFunction<T, String> classNameGenerator) Deprecated.
setPartNameGenerator(com.vaadin.flow.function.SerializableFunction<T, java.lang.String>)
should be used instead.protected void
setColumnKey
(String key, Grid.Column column) Sets a user-defined identifier for given column.
void
setColumnOrder
(Grid.Column<T>... columns) Sets a new column order for the grid.
void
setColumnOrder
(List<Grid.Column<T>> columns) Sets a new column order for the grid.
void
setColumnRendering
(ColumnRendering columnRendering) Sets the mode for rendering columns in the grid.
void
setColumnReorderingAllowed
(boolean columnReorderingAllowed) Sets whether or not column reordering is allowed.
void
setColumns
(String... propertyNames) Sets the columns and their order based on the given properties.
void
setDataProvider
(DataProvider<T, ?> dataProvider) Sets a generic data provider for the Grid to use.
static void
Sets the default multi-sort priority to use for all Grid instances.
void
setDetailsVisible
(T item, boolean visible) Sets the visibility of details component for given item.
void
setDetailsVisibleOnClick
(boolean detailsVisibleOnClick) Sets whether the item details can be opened and closed by clicking the rows or not.
void
setDragDataGenerator
(String type, SerializableFunction<T, String> dragDataGenerator) Sets a generator function for customizing drag data.
void
setDragFilter
(SerializablePredicate<T> dragFilter) Sets the drag filter for this drag source.
void
setDropFilter
(SerializablePredicate<T> dropFilter) Sets the drop filter for this drag target.
void
setDropMode
(GridDropMode dropMode) Sets the drop mode of this drop target.
void
setEmptyStateComponent
(Component emptyStateComponent) Sets the component to be displayed when the grid is empty.
void
setEmptyStateText
(String emptyStateText) Sets the text to be displayed when the grid is empty.
void
setItemDetailsRenderer
(Renderer<T> renderer) Set the renderer to use for displaying the item details rows in this grid.
setItems
(BackEndDataProvider<T, Void> dataProvider) Supply items with a
BackEndDataProvider
that lazy loads items from a backend.setItems
(DataProvider<T, Void> dataProvider) Set a generic data provider for the component to use and returns the base
DataView
that provides API to get information on the items.setItems
(InMemoryDataProvider<T> inMemoryDataProvider) Sets an in-memory data provider for the component to use
setItems
(ListDataProvider<T> dataProvider) Sets a ListDataProvider for the component to use and returns a
ListDataView
that provides information and allows operations on the items.void
setItemSelectableProvider
(SerializablePredicate<T> provider) Sets a predicate to check whether a specific item in the grid may be selected or deselected by the user.
setItemsPageable
(Grid.SpringData.FetchCallback<org.springframework.data.domain.Pageable, T> fetchCallback) Supply items lazily with a callback from a backend based on a Spring Data Pageable.
setItemsPageable
(Grid.SpringData.FetchCallback<org.springframework.data.domain.Pageable, T> fetchCallback, Grid.SpringData.CountCallback<org.springframework.data.domain.Pageable> countCallback) Supply items lazily with callbacks: the first one fetches a list of items from a backend based on a Spring Data Pageable, the second provides the exact count of items in the backend.
void
setMultiSort
(boolean multiSort) Sets whether multiple column sorting is enabled on the client-side.
void
setMultiSort
(boolean multiSort, boolean onShiftClickOnly) Sets whether multiple column sorting is enabled on the client-side.
void
setMultiSort
(boolean multiSort, Grid.MultiSortPriority priority) Sets whether multiple column sorting is enabled on the client-side.
void
setMultiSort
(boolean multiSort, Grid.MultiSortPriority priority, boolean onShiftClickOnly) Sets whether multiple column sorting is enabled on the client-side.
void
setNestedNullBehavior
(Grid.NestedNullBehavior nestedNullBehavior) Set the behavior when facing nested
null
values.void
setPageSize
(int pageSize) Sets the page size, which is the number of items fetched at a time from the data provider.
void
setPartNameGenerator
(SerializableFunction<T, String> partNameGenerator) Sets the function that is used for generating CSS part names for all the cells in the rows in this grid.
void
setRowsDraggable
(boolean rowsDraggable) Sets whether the user can drag the grid rows or not.
void
setSelectionDragDetails
(int draggedItemsCount, Map<String, String> dragData) Sets explicit drag operation details for when the user is dragging the selected items.
setSelectionMode
(Grid.SelectionMode selectionMode) Sets the grid's selection mode.
protected void
setSelectionModel
(GridSelectionModel<T> model, Grid.SelectionMode selectionMode) Sets the selection model for the grid.
void
setSelectionPreservationMode
(SelectionPreservationMode selectionPreservationMode) Sets the selection preservation mode.
void
setSortableColumns
(String... propertyNames) Sets the defined columns as sortable, based on the given property names.
void
setTooltipGenerator
(SerializableFunction<T, String> tooltipGenerator) Sets the function that is used for generating tooltip text for all cells in this grid.
void
setTooltipPosition
(Tooltip.TooltipPosition position) Sets the tooltip position relative to the cell that is being hovered or focused.
protected void
setUniqueKeyProperty
(String uniqueKeyProperty) Sets property name for unique key in row's generated JSON.
protected void
setUniqueKeyProvider
(ValueProvider<T, String> uniqueKeyProvider) Sets value provider for unique key in row's generated JSON.
void
sort
(List<GridSortOrder<T>> order) Forces a defined sort order for the columns in the Grid.
protected void
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, 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.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.data.provider.HasLazyDataView
setItems, setItems
Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView
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
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
Constructor Details
-
Grid
public Grid()Creates a new instance, with page size of 50.
-
Grid
Creates a new grid using the given generic
DataProvider
.Parameters:
dataProvider
- the data provider, notnull
-
Grid
Creates a new grid using the given
BackEndDataProvider
.Parameters:
dataProvider
- the data provider, notnull
-
Grid
Creates a new grid using the given
InMemoryDataProvider
.Parameters:
inMemoryDataProvider
- the data provider, notnull
-
Grid
Creates a new grid using the given
ListDataProvider
.Parameters:
dataProvider
- the data provider, notnull
-
Grid
Creates a new grid using the given collection of items using a
ListDataProvider
.Parameters:
items
- the collection of items, notnull
-
Grid
public Grid(int pageSize) Creates a new instance, with the specified page size.
The page size influences the
Query.getLimit()
sent by the client, but it's up to the webcomponent to determine the actual query limit, based on the height of the component and scroll position. Usually the limit is 3 times the page size (e.g. 150 items with a page size of 50).Parameters:
pageSize
- the page size. Must be greater than zero. -
Grid
Creates a new grid with an initial set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the
column keys
and the property captions will be used as thecolumn headers
. The generated columns will be sortable by default, if the property isComparable
.When autoCreateColumns is
true
, only the direct properties of the bean are included and they will be in alphabetical order. UsesetColumns(String...)
to define which properties to include and in which order. You can also add a column for an individual property withaddColumn(String)
. Both of these methods support also sub-properties with dot-notation, eg."property.nestedProperty"
.Parameters:
beanType
- the bean type to use, notnull
autoCreateColumns
- whentrue
, columns are created automatically for the properties of the beanType -
Grid
Creates a new grid with an initial set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the
column keys
and the property captions will be used as thecolumn headers
. The generated columns will be sortable by default, if the property isComparable
.By default, only the direct properties of the bean are included and they will be in alphabetical order. Use
setColumns(String...)
to define which properties to include and in which order. You can also add a column for an individual property withaddColumn(String)
. Both of these methods support also sub-properties with dot-notation, eg."property.nestedProperty"
.Parameters:
beanType
- the bean type to use, notnull
-
Grid
protected Grid(Class<T> beanType, SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueBuilder, B dataCommunicatorBuilder) Creates a new grid with an initial set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the
column keys
and the property captions will be used as thecolumn headers
.You can add columns for nested properties of the bean with
addColumn(String)
.Type Parameters:
B
- the data communicator builder typeU
- the GridArrayUpdater typeParameters:
beanType
- the bean type to use, notnull
updateQueueBuilder
- the builder for newGrid.UpdateQueue
instancedataCommunicatorBuilder
- Builder forDataCommunicator
implementation this Grid uses to handle all data communication. -
Grid
protected Grid(Class<T> beanType, SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueBuilder, B dataCommunicatorBuilder, boolean autoCreateColumns) Creates a new grid with an initial set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the
column keys
and the property captions will be used as thecolumn headers
.When autoCreateColumns is
true
, only the direct properties of the bean are included and they will be in alphabetical order. UsesetColumns(String...)
to define which properties to include and in which order. You can also add a column for an individual property withaddColumn(String)
. Both of these methods support also sub-properties with dot-notation, eg."property.nestedProperty"
.Type Parameters:
B
- the data communicator builder typeU
- the GridArrayUpdater typeParameters:
beanType
- the bean type to use, notnull
updateQueueBuilder
- the builder for newGrid.UpdateQueue
instancedataCommunicatorBuilder
- Builder forDataCommunicator
implementation this Grid uses to handle all data communication.autoCreateColumns
- whentrue
, columns are created automatically for the properties of the beanType -
Grid
protected Grid(int pageSize, SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueBuilder, B dataCommunicatorBuilder) Creates a new instance, with the specified page size and data communicator.
The page size influences the
Query.getLimit()
sent by the client, but it's up to the webcomponent to determine the actual query limit, based on the height of the component and scroll position. Usually the limit is 3 times the page size (e.g. 150 items with a page size of 50).Type Parameters:
B
- the data communicator builder typeU
- the GridArrayUpdater typeParameters:
pageSize
- the page size. Must be greater than zero.updateQueueBuilder
- the builder for newGrid.UpdateQueue
instancedataCommunicatorBuilder
- Builder forDataCommunicator
implementation this Grid uses to handle all data communication.
-
-
Method Details
-
setDefaultMultiSortPriority
Sets the default multi-sort priority to use for all Grid instances.
This method should be called before creating any Grid instances. Changing this setting does not affect the default for existing Grids. Use
setMultiSort(boolean, MultiSortPriority)
to provide a custom multi-sort priority overriding the default priority for a single Grid.Parameters:
priority
- the multi-sort priority to be used by all grid instances -
initConnector
protected void initConnector() -
createDefaultArrayUpdater
protected GridArrayUpdater createDefaultArrayUpdater(SerializableBiFunction<GridArrayUpdater.UpdateQueueData, Integer, Grid.UpdateQueue> updateQueueFactory) -
addColumn
Adds a new text column to this
Grid
with a value provider and default column factory. The value is converted to String when sent to the client by usingString.valueOf(Object)
.NOTE: For displaying components, see
addComponentColumn(ValueProvider)
. For using build-in renderers, seeaddColumn(Renderer)
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.NOTE: This method is a shorthand for
addColumn(ValueProvider, BiFunction)
Parameters:
valueProvider
- the value providerReturns:
the created column
See Also:
-
addColumn
protected <C extends Grid.Column<T>> C addColumn(ValueProvider<T, ?> valueProvider, BiFunction<Renderer<T>, String, C> columnFactory) Adds a new text column to this
Grid
with a value provider and column factory provided. The value is converted to String when sent to the client by usingString.valueOf(Object)
.NOTE: For displaying components, see
addComponentColumn(ValueProvider)
. For using build-in renderers, seeaddColumn(Renderer)
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.Parameters:
valueProvider
- the value providercolumnFactory
- the method that creates a new column instance for thisGrid
instance.Returns:
the created column
See Also:
-
addComponentColumn
public <V extends Component> Grid.Column<T> addComponentColumn(ValueProvider<T, V> componentProvider) Adds a new column that shows components.
This is a shorthand for
addColumn(Renderer)
with aComponentRenderer
.NOTE: Using
ComponentRenderer
is not as efficient as the built in renderers or usingLitRenderer
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.Type Parameters:
V
- the component typeParameters:
componentProvider
- a value provider that will return a component for the given itemReturns:
the new column
See Also:
-
addColumn
public <V extends Comparable<? super V>> Grid.Column<T> addColumn(ValueProvider<T, V> valueProvider, String... sortingProperties) Adds a new text column to this
Grid
with a value provider and sorting properties.The value is converted to a JSON value by usingJsonSerializer.toJson(Object)
. The sorting properties are used to configure backend sorting for this column. In-memory sorting is automatically configured using the return type of the givenValueProvider
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.Type Parameters:
V
- the type of the columnParameters:
valueProvider
- the value providersortingProperties
- the sorting properties to use with this columnReturns:
the created column
See Also:
-
addColumn
Adds a new text column to this
Grid
with a renderer and default column factory.See implementations of the
Renderer
interface for built-in renderer options with type safe APIs. For a renderer using template binding, useLitRenderer.of(String)
.NOTE: You can add component columns easily using the
addComponentColumn(ValueProvider)
, but usingComponentRenderer
is not as efficient as the built in renderers or usingLitRenderer
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.NOTE: This method is a shorthand for
addColumn(Renderer, BiFunction)
Parameters:
renderer
- the renderer used to create the grid cell structureReturns:
the created column
See Also:
-
addColumn
protected <C extends Grid.Column<T>> C addColumn(Renderer<T> renderer, BiFunction<Renderer<T>, String, C> columnFactory) Adds a new text column to this
Grid
with a renderer and column factory provided.See implementations of the
Renderer
interface for built-in renderer options with type safe APIs. For a renderer using template binding, useLitRenderer.of(String)
.NOTE: You can add component columns easily using the
addComponentColumn(ValueProvider)
, but usingComponentRenderer
is not as efficient as the built in renderers or usingLitRenderer
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.Parameters:
renderer
- the renderer used to create the grid cell structurecolumnFactory
- the method that creates a new column instance for thisGrid
instance.Returns:
the created column
See Also:
-
createColumn
Deprecated.This method should not be used outside.getDefaultColumnFactory()
should be used instead.Creates a new column instance for this
Grid
instance.This method must not return
null
.Parameters:
renderer
- the renderer used to create the grid cell structurecolumnId
- internal column idReturns:
column instance
See Also:
-
getDefaultColumnFactory
Gives a reference to the column factory.
This method must not return
null
.Returns:
method for column creation
-
addColumn
Adds a new column for the given property name with the default column factory. The property values are converted to Strings in the grid cells. The property's full name will be used as the
column key
and the property caption will be used as thecolumn header
.You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
If the property is
Comparable
, the created column is sortable by default. This can be changed with theGrid.Column.setSortable(boolean)
method.Note: This method can only be used for a Grid created from a bean type with
Grid(Class)
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.Note: This method is a shorthand for
addColumn(String, BiFunction)
Parameters:
propertyName
- the property name of the new column, notnull
Returns:
the created column
See Also:
-
addColumn
protected <C extends Grid.Column<T>> C addColumn(String propertyName, BiFunction<Renderer<T>, String, C> columnFactory) Adds a new column for the given property name with the column factory provided. The property values are converted to Strings in the grid cells. The property's full name will be used as the
column key
and the property caption will be used as thecolumn header
.You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
If the property is
Comparable
, the created column is sortable by default. This can be changed with theGrid.Column.setSortable(boolean)
method.Note: This method can only be used for a Grid created from a bean type with
Grid(Class)
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.Parameters:
propertyName
- the property name of the new column, notnull
columnFactory
- the method that creates a new column instance for thisGrid
instance.Returns:
the created column
See Also:
-
addColumns
Adds a new columns for the given property names. The property values are converted to Strings in the grid cells. The properties' full names will be used as the
column key
and the properties' caption will be used as thecolumn header
.You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
If the property is
Comparable
, the created column is sortable by default. This can be changed with theGrid.Column.setSortable(boolean)
method.Note: This method can only be used for a Grid created from a bean type with
Grid(Class)
.Every added column sends data to the client side regardless of its visibility state. Don't add a new column at all or use
removeColumn(Column)
to avoid sending extra data.Parameters:
propertyNames
- the property names of the new columns, notnull
See Also:
-
setColumns
Sets the columns and their order based on the given properties.
This is a shortcut for removing all columns and then calling
addColumn(String)
for each of the given propertyNames.You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
Note that this also resets the headers and footers.
Note: This method can only be used for a Grid created from a bean type with
Grid(Class)
.Parameters:
propertyNames
- the properties to create columns for -
setSortableColumns
Sets the defined columns as sortable, based on the given property names.
This is a shortcut for setting all columns not sortable and then calling
Grid.Column.setSortable(boolean)
for each of the columns defined by the given propertyNames.You can set sortable columns for nested properties with dot notation, eg.
"property.nestedProperty"
Note: This method can only be used for a Grid created from a bean type with
Grid(Class)
.Parameters:
propertyNames
- the property names used to reference the columnsThrows:
IllegalArgumentException
- if any of the propertyNames refers to a non-existing columnSee Also:
-
setColumnKey
Sets a user-defined identifier for given column.
Parameters:
column
- the columnkey
- the user-defined identifierSee Also:
-
createColumnId
-
prependHeaderRow
Adds a new header row on the top of the existing header rows.
If there are no existing header rows, this will create the first row.
Returns:
the created header row
-
appendHeaderRow
Adds a new header row to the bottom of the existing header rows.
If there are no existing header rows, this will create the first row.
Returns:
the created header row
-
removeHeaderRow
Removes the header row from the grid. Note that the default header row can be removed only if it is the only header row.
Parameters:
headerRow
- the header row to removeThrows:
UnsupportedOperationException
- if default row is being removed while there are other header rowsNoSuchElementException
- if the header row cannot be foundSee Also:
-
removeAllHeaderRows
public void removeAllHeaderRows()Removes all header rows from the grid.
See Also:
-
addFirstHeaderRow
-
getDefaultHeaderRow
-
getColumnLayers
-
getHeaderRows
Gets all of the header rows in the Grid, in order from top to bottom.
Returns:
the header rows of the Grid
-
addThemeVariants
Adds theme variants to the component.
Parameters:
variants
- theme variants to add -
removeThemeVariants
Removes theme variants from the component.
Parameters:
variants
- theme variants to remove -
insertColumnLayer
protected com.vaadin.flow.component.grid.ColumnLayer insertColumnLayer(int index, List<com.vaadin.flow.component.grid.AbstractColumn<?>> columns) Creates a new layer from the provided columns, inserts the layer into given index and returns the new layer.
The user of this method should make sure that the DOM corresponds the column layer structure.
Parameters:
index
- the index to insertcolumns
- the column components that the new layer will wrapReturns:
the new layer
-
removeColumnLayer
protected void removeColumnLayer(com.vaadin.flow.component.grid.ColumnLayer layer) Removes the given layer and moves the columns on the lower level to its place.
Parameters:
layer
- the layer to remove, not the bottom layer -
setDataProvider
Sets a generic data provider for the Grid to use.
Use this method when none of the
setItems
methods are applicable, e.g. when having a data provider with filter that cannot be transformed toDataProvider<T, Void>
.Parameters:
dataProvider
- DataProvider instance to use, notnull
-
getDataProvider
Returns the data provider of this grid.
To get information and control over the items in the grid, use either
getListDataView()
orgetLazyDataView()
instead.Returns:
the data provider of this grid, not
null
-
setItems
Description copied from interface:
HasDataView
Set a generic data provider for the component to use and returns the base
DataView
that provides API to get information on the items.This method should be used only when the data provider type is not either
ListDataProvider
orBackEndDataProvider
.Specified by:
setItems
in interfaceHasDataView<T,
Void, GridDataView<T>> Parameters:
dataProvider
- DataProvider instance to use, notnull
Returns:
DataView providing information on the data
-
setItems
Description copied from interface:
HasDataView
Sets an in-memory data provider for the component to use
Note! Using a
ListDataProvider
instead of aInMemoryDataProvider
is recommended to get access toListDataView
API by usingHasListDataView.setItems(ListDataProvider)
.Specified by:
setItems
in interfaceHasDataView<T,
Void, GridDataView<T>> Parameters:
inMemoryDataProvider
- InMemoryDataProvider to use, notnull
Returns:
DataView providing information on the data
-
getGenericDataView
Gets the generic data view for the grid. This data view should only be used when
getListDataView()
orgetLazyDataView()
is not applicable for the underlying data provider.Specified by:
getGenericDataView
in interfaceHasDataView<T,
Void, GridDataView<T>> Returns:
the generic
DataView
implementation for gridSee Also:
-
setItems
Description copied from interface:
HasListDataView
Sets a ListDataProvider for the component to use and returns a
ListDataView
that provides information and allows operations on the items.Specified by:
setItems
in interfaceHasListDataView<T,
GridListDataView<T>> Parameters:
dataProvider
- ListDataProvider providing items to the component.Returns:
ListDataView providing access to the items
-
getListDataView
Gets the list data view for the grid. This data view should only be used when the items are in-memory set with:
If the items are not in-memory an exception is thrown. When the items are fetched lazily, usegetLazyDataView()
instead.Specified by:
getListDataView
in interfaceHasListDataView<T,
GridListDataView<T>> Returns:
the list data view that provides access to the items in the grid
-
setItems
Description copied from interface:
HasLazyDataView
Supply items with a
BackEndDataProvider
that lazy loads items from a backend. Note that component will query the data provider for the item count. In case that is not desired for performance reasons, useHasLazyDataView.setItems(CallbackDataProvider.FetchCallback)
instead.The returned data view object can be used for further configuration, or later on fetched with
HasLazyDataView.getLazyDataView()
. For using in-memory data, likeCollection
, useHasListDataView.setItems(Collection)
instead.Specified by:
setItems
in interfaceHasLazyDataView<T,
Void, GridLazyDataView<T>> Parameters:
dataProvider
- BackEndDataProvider instanceReturns:
LazyDataView instance for further configuration
-
setItemsPageable
public GridLazyDataView<T> setItemsPageable(Grid.SpringData.FetchCallback<org.springframework.data.domain.Pageable, T> fetchCallback) Supply items lazily with a callback from a backend based on a Spring Data Pageable. The component will automatically fetch more items and adjust its size until the backend runs out of items. Usage example:
component.setItemsPageable(pageable -> orderService.getOrders(pageable));
The returned data view object can be used for further configuration, or later on fetched with
getLazyDataView()
. For using in-memory data, likeCollection
, useHasListDataView.setItems(Collection)
instead.Parameters:
fetchCallback
- a function that returns a sorted list of items from the backend based on the given pageableReturns:
a data view for further configuration
-
setItemsPageable
public GridLazyDataView<T> setItemsPageable(Grid.SpringData.FetchCallback<org.springframework.data.domain.Pageable, T> fetchCallback, Grid.SpringData.CountCallback<org.springframework.data.domain.Pageable> countCallback) Supply items lazily with callbacks: the first one fetches a list of items from a backend based on a Spring Data Pageable, the second provides the exact count of items in the backend. Use this in case getting the count is cheap and the user benefits from the component showing immediately the exact size. Usage example:
component.setItemsPageable( pageable -> orderService.getOrders(pageable), pageable -> orderService.countOrders());
The returned data view object can be used for further configuration, or later on fetched with
getLazyDataView()
. For using in-memory data, likeCollection
, useHasListDataView.setItems(Collection)
instead.Parameters:
fetchCallback
- a function that returns a sorted list of items from the backend based on the given pageablecountCallback
- a function that returns the number of items in the back endReturns:
LazyDataView instance for further configuration
-
getLazyDataView
Gets the lazy data view for the grid. This data view should only be used when the items are provided lazily from the backend with:
HasLazyDataView.setItems(CallbackDataProvider.FetchCallback)
HasLazyDataView.setItems(CallbackDataProvider.FetchCallback, CallbackDataProvider.CountCallback)
setItems(BackEndDataProvider)
getListDataView()
instead.Specified by:
getLazyDataView
in interfaceHasLazyDataView<T,
Void, GridLazyDataView<T>> Returns:
the lazy data view that provides access to the data bound to the grid
-
getDataCommunicator
Returns the data communicator of this Grid.
Returns:
the data communicator, not
null
-
getPageSize
public int getPageSize()Gets the current page size, which is the number of items fetched at a time from the dataprovider.
Returns:
the current page size
-
setPageSize
public void setPageSize(int pageSize) Sets the page size, which is the number of items fetched at a time from the data provider. With the default value of
50
, the grid might fetch items for example as:0-49, 50-149, 150-200...
.Note: the number of items in the server-side memory can be considerably higher than the page size, since the component can show more than one page at a time.
Setting the pageSize after the Grid has been rendered effectively resets the component, and the current page(s) and sent over again.
With automatically extending grid, controlling the item count and how much it is increased when scrolling is possible via
getLazyDataView()
.Parameters:
pageSize
- the maximum number of items sent per request. Should be greater than zero -
getSelectionModel
Returns the selection model for this grid.
Returns:
the selection model, not null
-
setSelectionModel
Sets the selection model for the grid.
This method is for setting a custom selection model, and is
protected
becausesetSelectionMode(SelectionMode)
should be used for easy switching between built-in selection models.The default selection model is
GridSingleSelectionModel
.To use a custom selection model, you can e.g. extend the grid call this method with your custom selection model.
Parameters:
model
- the selection model to use, notnull
selectionMode
- the selection mode this selection model corresponds to, notnull
See Also:
-
updateSelectionModeOnClient
protected void updateSelectionModeOnClient() -
getSelectionMode
Returns the selection mode for this grid.
Returns:
the selection mode, not null
-
setSelectionMode
Sets the grid's selection mode.
To use your custom selection model, you can use
setSelectionModel(GridSelectionModel, SelectionMode)
, see existing selection model implementations for example.Parameters:
selectionMode
- the selection mode to switch to, notnull
Returns:
the used selection model
See Also:
-
setItemSelectableProvider
Sets a predicate to check whether a specific item in the grid may be selected or deselected by the user. The predicate receives an item instance and should return
true
if a user may change the selection state of that item, orfalse
otherwise.This function does not prevent programmatic selection/deselection of items. Changing the function does not modify the currently selected items.
When using multi-selection, setting a provider will hide the select all checkbox.
Parameters:
provider
- the function to use to determine whether an item may be selected or deselected by the user, ornull
to allow all items to be selected or deselected -
asSingleSelect
Use this grid as a single select in
Binder
.Throws
IllegalStateException
if the grid is not using aGridSingleSelectionModel
.Returns:
the single select wrapper that can be used in binder
Throws:
IllegalStateException
- if not using a single selection model -
asMultiSelect
Use this grid as a multiselect in
Binder
.Throws
IllegalStateException
if the grid is not using aGridMultiSelectionModel
.Returns:
the multiselect wrapper that can be used in binder
Throws:
IllegalStateException
- if not using a multiselection model -
getSelectedItems
This method is a shorthand that delegates to the currently set selection model.
Returns:
a set with the selected items, never
null
See Also:
-
select
This method is a shorthand that delegates to the currently set selection model.
Parameters:
item
- the item to select, not nullSee Also:
-
deselect
This method is a shorthand that delegates to the currently set selection model.
Parameters:
item
- the item to deselect, not nullSee Also:
-
deselectAll
public void deselectAll()This method is a shorthand that delegates to the currently set selection model.
See Also:
-
getSelectionPreservationMode
Gets the selection preservation mode.
Returns:
the selection preservation mode
See Also:
-
addSelectionListener
Adds a selection listener to the current selection model.
This is a shorthand for
grid.getSelectionModel().addSelectionListener()
. To get more detailed selection events, usegetSelectionModel()
and eitherGridSingleSelectionModel.addSingleSelectionListener(SingleSelectionListener)
orGridMultiSelectionModel.addMultiSelectionListener(MultiSelectionListener)
depending on the used selection mode.Parameters:
listener
- the listener to addReturns:
a registration handle to remove the listener
Throws:
UnsupportedOperationException
- if selection has been disabled withGrid.SelectionMode.NONE
-
setItemDetailsRenderer
Set the renderer to use for displaying the item details rows in this grid.
Parameters:
renderer
- the renderer to use for displaying item details rows,null
to remove the current renderer -
isColumnReorderingAllowed
Returns whether column reordering is allowed. Default value is
false
.Returns:
true if reordering is allowed
-
setColumnReorderingAllowed
public void setColumnReorderingAllowed(boolean columnReorderingAllowed) Sets whether or not column reordering is allowed. Default value is
false
.Parameters:
columnReorderingAllowed
- specifies whether column reordering is allowed -
getColumns
Gets an unmodifiable list of all
Grid.Column
s currently in thisGrid
.Note: If column reordering is enabled with
setColumnReorderingAllowed(boolean)
and the user has reordered the columns, the order of the list returned by this method might be incorrect.Returns:
unmodifiable list of columns
-
getColumnByKey
Gets a
Grid.Column
of this grid by its key.Parameters:
columnKey
- the identifier key of the column to getReturns:
the column corresponding to the given column key, or
null
if no column has such keySee Also:
-
removeColumnByKey
Removes a column with the given column key from the Grid.
Parameters:
columnKey
- the key of the column, assigned byGrid.Column.setKey(String)
, or automatically created when usingGrid(Class)
. Cannot benull
Throws:
IllegalArgumentException
- if the column is not part of this Grid -
removeColumn
Removes a column from the Grid.
Parameters:
column
- the column to be removed, notnull
Throws:
NullPointerException
- if the column isnull
IllegalArgumentException
- if the column is not owned by this Grid -
removeColumns
Removes columns from the Grid. Does nothing if the array is empty.
Parameters:
columns
- the columns to be removed, notnull
Throws:
NullPointerException
- if the column isnull
IllegalArgumentException
- if the column is not owned by this Grid -
removeAllColumns
public void removeAllColumns()Removes all columns from this Grid.
-
setDetailsVisible
Sets the visibility of details component for given item.
Parameters:
item
- the item to show details forvisible
-true
if details component should be visible;false
if it should be hidden -
setDetailsVisibleOnClick
public void setDetailsVisibleOnClick(boolean detailsVisibleOnClick) Sets whether the item details can be opened and closed by clicking the rows or not.
Parameters:
detailsVisibleOnClick
-true
to enable opening and closing item details by clicking the rows,false
to disable this functionalitySee Also:
-
isDetailsVisibleOnClick
public boolean isDetailsVisibleOnClick()Gets whether the item details are opened and closed by clicking the rows or not.
Returns:
true
if clicking the rows opens and closes their item details,false
otherwiseSee Also:
-
isDetailsVisible
Returns the visibility of details component for given item.
Parameters:
item
- the item to show details forReturns:
true
if details component should be visible;false
if it should be hidden -
addSortListener
public Registration addSortListener(ComponentEventListener<SortEvent<Grid<T>, GridSortOrder<T>>> listener) Description copied from interface:
SortEvent.SortNotifier
Adds a sort order change listener that gets notified when the sort order changes.
Specified by:
addSortListener
in interfaceSortEvent.SortNotifier<Grid<T>,
GridSortOrder<T>> Parameters:
listener
- the sort order change listener to addReturns:
a registration object for removing the listener
-
setMultiSort
public void setMultiSort(boolean multiSort) Sets whether multiple column sorting is enabled on the client-side.
Parameters:
multiSort
-true
to enable sorting of multiple columns on the client-side,false
to disable -
setMultiSort
Sets whether multiple column sorting is enabled on the client-side.
Parameters:
multiSort
-true
to enable sorting of multiple columns on the client-side,false
to disablepriority
- the multi-sort priority to set, notnull
See Also:
-
setMultiSort
public void setMultiSort(boolean multiSort, boolean onShiftClickOnly) Sets whether multiple column sorting is enabled on the client-side.
Parameters:
multiSort
-true
to enable sorting of multiple columns on the client-side,false
to disableonShiftClickOnly
-true
to enable multi-sort by shift-clicking (whenmultiSort = true
),false
for normal multi-sort behavior -
setMultiSort
public void setMultiSort(boolean multiSort, Grid.MultiSortPriority priority, boolean onShiftClickOnly) Sets whether multiple column sorting is enabled on the client-side.
Parameters:
multiSort
-true
to enable sorting of multiple columns on the client-side,false
to disablepriority
- the multi-sort priority to set, notnull
onShiftClickOnly
-true
to enable multi-sort by shift-clicking (whenmultiSort = true
),false
for normal multi-sort behaviorSee Also:
-
isMultiSort
public boolean isMultiSort()Gets whether multiple column sorting is enabled on the client-side.
Returns:
true
if sorting of multiple columns is enabled,false
otherwiseSee Also:
-
setAriaLabel
Set the aria-label of the component to the given text.
Parameters:
ariaLabel
- the aria-label text to set ornull
to clear -
getAriaLabel
Gets the aria-label of the component.
Returns:
an optional aria-label of the component if no aria-label has been set
-
addContextMenu
Adds a new context-menu for this grid.
Returns:
the added context-menu
-
sort
Forces a defined sort order for the columns in the Grid. Setting
null
or an empty list resets the ordering of all columns. Columns not mentioned in the list are reset to the unsorted state.For Grids with multi-sorting, the index of a given column inside the list defines the sort priority. For example, the column at index 0 of the list is sorted first, then on the index 1, and so on.
When Grid is not configured to have multi-sorting enabled, all the columns in the list except the first one are ignored.
Parameters:
order
- the list of sort orders to set on the client, ornull
to reset any sort orders.See Also:
-
onAttach
Description copied from class:
Component
Called when the component is attached to a UI.
This method is invoked before the
Make sure to callAttachEvent
is fired for the component.super.onAttach
when overriding this method. -
onDetach
Description copied from class:
Component
Called when the component is detached from a UI.
This method is invoked before the
DetachEvent
is fired for the component.Make sure to call
super.onDetach
when overriding this method. -
getSortOrder
Gets an list of the current sort orders in the Grid.
Returns:
an unmodifiable list of sort orders
-
createSortingComparator
Creates a comparator for grid to sort rows.
Returns:
the comparator based on column sorting information.
-
setAllRowsVisible
public void setAllRowsVisible(boolean allRowsVisible) If
true
, the grid's height is defined by its rows. All items are fetched from theDataProvider
, and the Grid shows no vertical scroll bar.Note:
setAllRowsVisible
disables the grid's virtual scrolling so that all the rows are rendered in the DOM at once. If the grid has a large number of items, using the feature is discouraged to avoid performance issues.Parameters:
allRowsVisible
-true
to make Grid compute its height by the number of rows,false
for the default behavior -
isAllRowsVisible
Gets whether grid's height is defined by the number of its rows.
Returns:
true
if Grid computes its height by the number of rows,false
otherwise -
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 classComponent
Parameters:
enabled
- the new enabled state of the component -
addValueProvider
Adds a ValueProvider to this Grid that is not tied to a Column. This is specially useful when the columns are defined via a template file instead of the Java API.
The properties added to by this method are global to the Grid - they can be used in any column.
ValueProviders are registered as
DataGenerator
s in the Grid. SeeaddDataGenerator(DataGenerator)
.Parameters:
property
- the property name used in the template. For example, in a template the uses[[item.name]]
, the property isname
. Notnull
valueProvider
- the provider for values for the property, notnull
Returns:
a registration that can be used to remove the ValueProvider from the Grid
-
addDataGenerator
Description copied from interface:
HasDataGenerators
Adds the given data generator. If the generator was already added, does nothing.
Specified by:
addDataGenerator
in interfaceHasDataGenerators<T>
Parameters:
dataGenerator
- the data generator to addReturns:
a registration that can be used to remove the data generator
-
compareMaybeComparables
-
configureBeanType
Sets the bean type this grid is bound to and optionally adds a set of columns for each of the bean's properties. The property-values of the bean will be converted to Strings. Full names of the properties will be used as the
column keys
and the property captions will be used as thecolumn headers
. The generated columns will be sortable by default, if the property isComparable
.When autoCreateColumns is
true
, only the direct properties of the bean are included and they will be in alphabetical order. UsesetColumns(String...)
to define which properties to include and in which order. You can also add a column for an individual property withaddColumn(String)
. Both of these methods support also sub-properties with dot-notation, eg."property.nestedProperty"
.This method can only be called for a newly instanced Grid without any beanType or columns set.
Parameters:
beanType
- the bean type to use, notnull
autoCreateColumns
- whentrue
, columns are created automatically for the properties of the beanType -
getBeanType
Returns the Class of bean this Grid is constructed with via
Grid(Class)
. Or null if not constructed from a bean type.Returns:
the Class of bean this Grid is constructed with
-
getPropertySet
Returns
PropertySet
of bean this Grid is constructed with viaGrid(Class)
. Or null if not constructed from a bean type.Returns:
the
PropertySet
of bean this Grid is constructed with -
addItemClickListener
Adds an item click listener to this component.
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
See Also:
-
addColumnResizeListener
Adds a column resize listener to this component. Note that the listener will be notified only for user-initiated column resize actions.
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
-
addItemDoubleClickListener
public Registration addItemDoubleClickListener(ComponentEventListener<ItemDoubleClickEvent<T>> listener) Adds an item double click listener to this component.
Note that double click event happens along with a click event. It means there is no way to get a double click event only (double click without a click): a click listener added using
addItemClickListener(ComponentEventListener)
(if any) will also be notified about a click event once a double click event is fired.Double click event type is not fully supported by the mobile browsers which means that double click event might not work (double click listeners won't be notified) for such browsers.
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
See Also:
-
addCellFocusListener
Adds a listener to the grid that will be notified, when a cell has been focused.
The listener will be notified, when- the navigation focus of a cell gets activated
- the focus is restored to the browser if a cell had navigation focus before the focus was lost
- the navigation focus moves between header/body/footer sections
The listener will not be notified, when- the focus changes between focusable elements in the Grid cells ("interaction mode")
- on Grid Pro edit mode navigation ("interaction mode")
- the focus changes between focusable elements in the cells in Flow Grid's editor mode ("interaction mode")
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
-
getEditor
Gets the editor.
The editor is created using
createEditor()
.Returns:
the editor instance
See Also:
-
setClassNameGenerator
Deprecated.setPartNameGenerator(com.vaadin.flow.function.SerializableFunction<T, java.lang.String>)
should be used instead.Sets the function that is used for generating CSS class names for all the cells in the rows in this grid. Returning
null
from the generator results in no custom class name being set. Multiple class names can be returned from the generator as space-separated.If
Grid.Column.setClassNameGenerator(SerializableFunction)
is used together with this method, resulting class names from both methods will be effective. Class names generated by grid are applied to the cells before the class names generated by column. This means that if the classes contain conflicting style properties, column's classes will win.Parameters:
classNameGenerator
- the class name generator to set, notnull
Throws:
NullPointerException
- ifclassNameGenerator
isnull
See Also:
-
setPartNameGenerator
Sets the function that is used for generating CSS part names for all the cells in the rows in this grid. Returning
null
from the generator results in no custom part name being set. Multiple part names can be returned from the generator as space-separated.If
Grid.Column.setPartNameGenerator(SerializableFunction)
is used together with this method, resulting part names from both methods will be effective.Parameters:
partNameGenerator
- the part name generator to set, notnull
Throws:
NullPointerException
- ifpartNameGenerator
isnull
See Also:
-
recalculateColumnWidths
public void recalculateColumnWidths()Updates the
width
of all columns which haveautoWidth
set totrue
.See Also:
-
getClassNameGenerator
Gets the function that is used for generating CSS class names for rows in this grid.
Returns:
the class name generator
-
getPartNameGenerator
Gets the function that is used for generating CSS part names for rows in this grid.
Returns:
the part name generator
-
createEditor
Creates a new Editor instance. Can be overridden to create a custom Editor. If the Editor is a
Grid.AbstractGridExtension
, it will be automatically added toDataCommunicator
.Returns:
editor
-
getUniqueKeyProvider
Gets optional value provider for unique key in row's generated JSON.
Returns:
ValueProvider for unique key for row or null if not set
-
setUniqueKeyProvider
Sets value provider for unique key in row's generated JSON.
null
by default.Parameters:
uniqueKeyProvider
- ValueProvider for unique key for row -
getUniqueKeyProperty
Gets property name for unique key in row's generated JSON.
Returns:
the optional property name for unique key
-
setUniqueKeyProperty
Sets property name for unique key in row's generated JSON.
Parameters:
uniqueKeyProperty
- the new optional property name for unique key -
getArrayUpdater
-
onDataProviderChange
protected void onDataProviderChange()Callback which is called if a new data provider is set or any change happen in the current data provider (an
DataChangeEvent
event is fired). Default implementation closes the editor if it's opened.See Also:
-
addDropListener
Adds a drop listener to this component.
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
-
addDragStartListener
Adds a drag start listener to this component.
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
-
addDragEndListener
Adds a drag end listener to this component.
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
-
setDropMode
Sets the drop mode of this drop target. When set to not
null
, grid fires drop events upon data drop over the grid or the grid rows.When using
GridDropMode.ON_TOP
, and the grid is either empty or has empty space after the last row, the drop can still happen on the empty space, and theGridDropEvent.getDropTargetItem()
will return an empty optional.When using
GridDropMode.BETWEEN
orGridDropMode.ON_TOP_OR_BETWEEN
, and there is at least one row in the grid, any drop after the last row in the grid will get the last row as theGridDropEvent.getDropTargetItem()
. If there are no rows in the grid, then it will return an empty optional.If using
GridDropMode.ON_GRID
, then the drop will not happen on any row, but instead just "on the grid". The target row will not be present in this case.NOTE: Prefer not using a row specific
GridDropMode
with a grid that enables sorting. If for example a new row gets added to a specific location on drop event, it might not end up in the location of the drop but rather where the active sorting configuration prefers to place it. This behavior might feel unexpected for the users.Parameters:
dropMode
- Drop mode that describes the allowed drop locations within the Grid's row. Can benull
to disable dropping on the grid.See Also:
-
getDropMode
Gets the drop mode of this drop target.
Returns:
Drop mode that describes the allowed drop locations within the Grid's row.
null
if dropping is not enabled. -
setRowsDraggable
public void setRowsDraggable(boolean rowsDraggable) Sets whether the user can drag the grid rows or not.
Parameters:
rowsDraggable
-true
if the rows can be dragged by the user;false
if not -
isRowsDraggable
public boolean isRowsDraggable()Gets whether rows of the grid can be dragged.
Returns:
true
if the rows are draggable,false
otherwise -
getDropFilter
Gets the active drop filter.
Returns:
The drop filter function
-
getDragFilter
Gets the active drag filter.
Returns:
The drag filter function
-
setDropFilter
Sets the drop filter for this drag target.
When the drop mode of the grid has been set to one of
GridDropMode.BETWEEN
,GridDropMode.ON_TOP
orGridDropMode.ON_TOP_OR_BETWEEN
, by default all the visible rows can be dropped over.A drop filter function can be used to specify the rows that are available for dropping over. The function receives an item and should return
true
if the row can be dropped over,false
otherwise.NOTE: If the filter conditions depend on a specific row that's currently being dragged, you might want to have the grid's drop mode disabled by default and set its value only on drag start to avoid the small period of time during which the user might be able to drop over unwanted rows. Once the drop end event occurs, the drop mode can be set back to
null
to keep this consistent.NOTE: If the filtering conditions change dynamically, remember to explicitly invoke
getDataProvider().refreshItem(item)
for the relevant items to get the filters re-run for them. -
setDragFilter
Sets the drag filter for this drag source.
When the
setRowsDraggable(boolean)
has been used to enable dragging, by default all the visible rows can be dragged.A drag filter function can be used to specify the rows that are available for dragging. The function receives an item and returns
true
if the row can be dragged,false
otherwise.NOTE: If the filtering conditions change dynamically, remember to explicitly invoke
getDataProvider().refreshItem(item)
for the relevant items to get the filters re-run for them. -
setDragDataGenerator
Sets a generator function for customizing drag data. The generated value will be accessible using the same
type
as the generator is set here. The function is executed for each item in the Grid during data generation. Return aString
to be appended to the row astype
data.Note that IE11 only supports data type "text"
Parameters:
type
- Type of the generated data. The generated value will be accessible during drop using this type.dragDataGenerator
- Function to be executed on row data generation. -
setTooltipGenerator
Sets the function that is used for generating tooltip text for all cells in this grid. Tooltip generators set to individual columns have priority over the generator set with this method. Returning
null
from the generator results in no tooltip being set.Parameters:
tooltipGenerator
- the tooltip generator to set, notnull
Throws:
NullPointerException
- iftooltipGenerator
isnull
Since:
24.1
-
getTooltipPosition
Gets the tooltip position relative to the cell that is being hovered or focused. The default position is
Tooltip.TooltipPosition.BOTTOM
.Returns:
the position of the tooltip
-
setSelectionDragDetails
Sets explicit drag operation details for when the user is dragging the selected items. By default, the drag data only covers the items in the visible viewport and all the items outside of it, even if selected, are excluded. Use this method to override the default drag data and the number shown in drag image on selection drag.
Note that IE11 only supports data type "text"
Parameters:
draggedItemsCount
- The number shown in the drag image on selection drag. Only values above 1 have any visible effect.dragData
- The drag data for selection drag. The map should consist of data type:data -entries -
addColumnReorderListener
public Registration addColumnReorderListener(ComponentEventListener<ColumnReorderEvent<T>> listener) Adds a column reorder listener to this component.
Parameters:
listener
- the listener to add, notnull
Returns:
a handle that can be used for removing the listener
-
setColumnOrder
Sets a new column order for the grid.
The function doesn't support column removal: all columns must be present in the list, otherwise
IllegalArgumentException
is thrown.The
getColumns()
function will reflect the new column ordering.Fires the
ColumnReorderEvent
withComponentEvent.isFromClient()
returningfalse
.The method is atomic: if the requested reordering is not achievable, the function fails cleanly with
IllegalArgumentException
without doing any work.Parameters:
columns
- the new ordering of the columns, notnull
.Throws:
NullPointerException
- if thecolumns
parameter isnull
.IllegalArgumentException
- if a column is present two times in the list, or if the column is not owned by this Grid, or if the list doesn't contain all columns currently present in the Grid, or if the column rearranging would require to split a joined header/footer cell group.See Also:
-
setColumnOrder
Sets a new column order for the grid.
The function doesn't support column removal: all columns must be present in the list, otherwise
IllegalArgumentException
is thrown.The
getColumns()
function will reflect the new column ordering.Fires the
ColumnReorderEvent
withComponentEvent.isFromClient()
returningfalse
.The method is atomic: if the requested reordering is not achievable, the function fails cleanly with
IllegalArgumentException
without doing any work.Parameters:
columns
- the new ordering of the columns, notnull
.Throws:
NullPointerException
- if thecolumns
parameter isnull
.IllegalArgumentException
- if a column is present two times in the list, or if the column is not owned by this Grid, or if the list doesn't contain all columns currently present in the Grid, or if the column rearranging would require to split a joined header/footer cell group.See Also:
-
scrollToIndex
public void scrollToIndex(int rowIndex) Scrolls to the given row index. Scrolls so that the row 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. -
scrollToItem
Scrolls to the row presenting the given item.
Note that the item index provider should be explicitly set using
AbstractLazyDataView.setItemIndexProvider(ItemIndexProvider)
for lazy loading data providers. Otherwise, anUnsupportedOperationException
will be thrown.Parameters:
item
- the item to scroll to, notnull
.Throws:
NullPointerException
- if theitem
parameter isnull
.NoSuchElementException
- if theitem
cannot be found.UnsupportedOperationException
- ifItemIndexProvider
is missing for grid with a lazy loading data provider. -
scrollToStart
public void scrollToStart()Scrolls to the beginning of the first data row.
-
scrollToEnd
public void scrollToEnd()Scrolls to the last data row of the grid.
-
setNestedNullBehavior
Set the behavior when facing nested
null
values. By default the value isNestedNullBehavior.THROW
.Parameters:
nestedNullBehavior
- the behavior when facing nestednull
values. -
getNestedNullBehavior
Get the behavior when facing nested
null
values.Returns:
The current behavior when facing nested
null
values. -
setColumnRendering
Sets the mode for rendering columns in the grid.
eager (default): All columns are rendered upfront, regardless of their visibility within the viewport. This mode should generally be preferred, as it avoids the limitations imposed by the "lazy" mode. Use this mode unless the grid has a large number of columns and performance outweighs the limitations in priority.
lazy: Optimizes the rendering of cells when there are multiple columns in the grid by virtualizing horizontal scrolling. In this mode, body cells are rendered only when their corresponding columns are inside the visible viewport.
Using "lazy" rendering should be used only if you're dealing with a large number of columns and performance is your highest priority. For most use cases, the default "eager" mode is recommended due to the limitations imposed by the "lazy" mode.
When using the "lazy" mode, keep the following limitations in mind:
- Row Height: When only a number of columns are visible at once, the height of a row can only be that of the highest cell currently visible on that row. Make sure each cell on a single row has the same height as all other cells on that row. If row cells have different heights, users may experience jumpiness when scrolling the grid horizontally as lazily rendered cells with different heights are scrolled into view.
- Auto-width Columns: For the columns that are initially outside the visible viewport but still use auto-width, only the header content is taken into account when calculating the column width because the body cells of the columns outside the viewport are not initially rendered.
- Screen Reader Compatibility: Screen readers may not be able to associate the focused cells with the correct headers when only a subset of the body cells on a row is rendered.
- Keyboard Navigation: Tabbing through focusable elements inside the grid body may not work as expected because some of the columns that would include focusable elements in the body cells may be outside the visible viewport and thus not rendered.
Parameters:
columnRendering
- the column rendering mode to useSee Also:
-
getColumnRendering
Gets the current column rendering mode.
Returns:
the current column rendering mode
-
setEmptyStateComponent
Sets the component to be displayed when the grid is empty.
Note: This will also override any empty state content set with
setEmptyStateText(String)
.Parameters:
emptyStateComponent
- the component to be displayed when the grid is empty, or null to clear the empty state content -
setEmptyStateText
Sets the text to be displayed when the grid is empty.
Note: This will also override any empty state content set with
setEmptyStateComponent(Component)
.Parameters:
emptyStateText
- the text to be displayed when the grid is empty, or null to clear the empty state content -
getEmptyStateComponent
Returns the component that is displayed when the grid is empty.
Returns:
the component that is displayed when the grid is empty or null if no empty state component is set
-
getEmptyStateText
Returns the text that is displayed when the grid is empty.
Returns:
the text that is displayed when the grid is empty or null if no empty state text is set
-