Class VGrid<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.grid.Grid<T>
org.vaadin.firitin.components.grid.VGrid<T>
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.grid.Grid<T>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.grid.Grid<T>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.grid.Grid<T>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.data.event.SortEvent.SortNotifier<com.vaadin.flow.component.grid.Grid<T>, com.vaadin.flow.component.grid.GridSortOrder<T>>, com.vaadin.flow.data.provider.HasDataGenerators<T>, com.vaadin.flow.data.provider.HasDataView<T, Void, com.vaadin.flow.component.grid.dataview.GridDataView<T>>, com.vaadin.flow.data.provider.HasLazyDataView<T, Void, com.vaadin.flow.component.grid.dataview.GridLazyDataView<T>>, com.vaadin.flow.data.provider.HasListDataView<T, com.vaadin.flow.component.grid.dataview.GridListDataView<T>>, Serializable, FluentAttachNotifier<VGrid<T>>, FluentBlurNotifier<com.vaadin.flow.component.grid.Grid<T>, VGrid<T>>, FluentComponent<VGrid<T>>, FluentDetachNotifier<VGrid<T>>, FluentFocusable<com.vaadin.flow.component.grid.Grid<T>, VGrid<T>>, FluentFocusNotifier<com.vaadin.flow.component.grid.Grid<T>, VGrid<T>>, FluentHasSize<VGrid<T>>, FluentHasStyle<VGrid<T>>, FluentHasTheme<VGrid<T>>
- Direct Known Subclasses:
GridMultiSelect, GridSelect, PagingGrid, TreeTable
public class VGrid<T>
extends com.vaadin.flow.component.grid.Grid<T>
implements FluentComponent<VGrid<T>>, FluentHasStyle<VGrid<T>>, FluentHasSize<VGrid<T>>, FluentFocusable<com.vaadin.flow.component.grid.Grid<T>, VGrid<T>>, FluentHasTheme<VGrid<T>>
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn interface to configure formatting of all data cells in the Grid.static interfaceUsed to assignStylerules to row cells.static classNested classes/interfaces inherited from class com.vaadin.flow.component.grid.Grid
com.vaadin.flow.component.grid.Grid.AbstractGridExtension<T>, com.vaadin.flow.component.grid.Grid.Column<T>, com.vaadin.flow.component.grid.Grid.DataCommunicatorBuilder<T,U>, com.vaadin.flow.component.grid.Grid.MultiSortPriority, com.vaadin.flow.component.grid.Grid.NestedNullBehavior, com.vaadin.flow.component.grid.Grid.SelectionMode, com.vaadin.flow.component.grid.Grid.SpringData, com.vaadin.flow.component.grid.Grid.UpdateQueue Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <C extends com.vaadin.flow.component.grid.Grid.Column<T>>
CaddColumn(com.vaadin.flow.function.ValueProvider<T, ?> valueProvider, BiFunction<com.vaadin.flow.data.renderer.Renderer<T>, String, C> columnFactory) com.vaadin.flow.component.grid.Grid.Column<T> final voidaddColumns(PropertyRef<T, ?>... properties) Adds columns for the given properties, using method references to their getters instead of property name strings.addPropertyColumn(PropertyRef<T, ?> property) Adds a column for the given property, using a method reference to its getter instead of a property name string:protected voidautoConfigureFromGetterReference(com.vaadin.flow.component.grid.Grid.Column<T> column, com.vaadin.flow.function.ValueProvider<T, ?> valueProvider) If the given value provider is a method reference to a getter, configures the column likeaddColumn(String)would: the property name becomes the column key, the property caption becomes the header and a column of aComparableproperty becomes sortable.voidfocus()protected List<tools.jackson.databind.introspect.BeanPropertyDefinition> getColumnByKey(PropertyRef<T, ?> property) Finds the column of the given property, using a method reference to its getter instead of a property name string.protected BiFunction<com.vaadin.flow.data.renderer.Renderer<T>, String, com.vaadin.flow.component.grid.Grid.Column<T>> hideProperties(String... propertyNamesToHide) Hides given columns.hideProperties(PropertyRef<T, ?>... propertiesToHide) Hides given columns, using method references to the getters instead of property name strings.booleanvoidremoveColumnByKey(PropertyRef<T, ?> property) Removes the column of the given property, using a method reference to its getter instead of a property name string.voidscrollToItem(T item) Deprecated.Note, with lazy loaded content, calling this method may cause performance issuesvoidsetAutoConfigureFromGetterReferences(boolean autoConfigureFromGetterReferences) Defines whether columns added with a method reference to a getter, likegrid.addColumn(Person::getFirstName), are configured with the key, header and sortability of that property.static voidsetAutoConfigureFromGetterReferencesByDefault(boolean autoConfigure) Defines the default ofsetAutoConfigureFromGetterReferences(boolean)for grids created after this call.final voidsetColumnOrder(PropertyRef<T, ?>... properties) Sets the order of the columns, using method references to the getters instead of property name strings.voidsetColumns(String... propertyNames) final voidsetColumns(PropertyRef<T, ?>... properties) Configures the columns shown by the grid, using method references to the getters instead of property name strings:setComponentRenderer(String columnKey, com.vaadin.flow.function.ValueProvider<T, C> componentProvider) Replaces the way the column with the given key is rendered, leaving everything else about the column as it is.setComponentRenderer(PropertyRef<T, ?> property, com.vaadin.flow.function.ValueProvider<T, C> componentProvider) Replaces the way the column of the given property is rendered, leaving everything else about the column as it is: its position among the other columns, its key, header, width and sorting all stay put.setDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T, Void> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<T, Void> countCallback) setRenderer(String columnKey, com.vaadin.flow.data.renderer.Renderer<T> renderer) Replaces the renderer of the column with the given key, leaving everything else about the column as it is.setRenderer(PropertyRef<T, ?> property, com.vaadin.flow.data.renderer.Renderer<T> renderer) Replaces the renderer of the column of the given property, leaving everything else about the column as it is.final voidsetSortableColumns(PropertyRef<T, ?>... properties) Makes the columns of the given properties sortable, using method references to their getters instead of property name strings.withCellFormatter(VGrid.CellFormatter<T> formatter) Defines a formatter used for all basic data columns.Adds a Vaadin 3,4,5,6,7,8 style column selector.withItems(Collection<T> items) withProperties(String... propertyNames) withProperties(PropertyRef<T, ?>... properties) Configures the columns shown by the grid, using method references to the getters instead of property name strings:withRowStyler(VGrid.RowStyler<T> rowStyler) Adds a strategy to style cells based on rows.withSelectionMode(com.vaadin.flow.component.grid.Grid.SelectionMode selectionMode) withSelectionModel(com.vaadin.flow.component.grid.GridSelectionModel<T> selectionModel, com.vaadin.flow.component.grid.Grid.SelectionMode selectionMode) withThemeVariants(com.vaadin.flow.component.grid.GridVariant... variants) Methods inherited from class com.vaadin.flow.component.grid.Grid
addCellFocusListener, addColumn, addColumn, addColumn, addColumn, addColumn, addColumnReorderListener, addColumnResizeListener, addColumns, addComponentColumn, addContextMenu, addDataGenerator, addDragEndListener, addDragStartListener, addDropListener, addFirstHeaderRow, addItemClickListener, addItemDoubleClickListener, addSelectionListener, addSortListener, addThemeVariants, addValueProvider, appendFooterRow, appendHeaderRow, asMultiSelect, asSingleSelect, compareMaybeComparables, configureBeanType, createColumn, createColumnId, createDefaultArrayUpdater, createEditor, createSortingComparator, deselect, deselectAll, getAriaLabel, getArrayUpdater, getBeanType, getColumnByInternalId, getColumnByKey, getColumnLayers, getColumnRendering, getColumns, getDataCommunicator, getDataProvider, getDefaultHeaderRow, getDragFilter, getDropFilter, getDropMode, getEditor, getEmptyStateComponent, getEmptyStateText, getFooterRows, getGenericDataView, getHeaderRows, getLazyDataView, getListDataView, getNestedNullBehavior, getPageSize, getPartNameGenerator, getPropertySet, getSelectedItems, getSelectionMode, getSelectionModel, getSelectionPreservationMode, getSortOrder, getTooltipPosition, getUniqueKeyProperty, getUniqueKeyProvider, initConnector, insertColumnLayer, isAllRowsVisible, isColumnReorderingAllowed, isDetailsVisible, isDetailsVisibleOnClick, isMultiSort, isRowsDraggable, isTooltipMarkdownEnabled, onAttach, onDataProviderChange, onDetach, onEnabledStateChanged, prependFooterRow, prependHeaderRow, recalculateColumnWidths, refreshViewport, removeAllColumns, removeAllFooterRows, removeAllHeaderRows, removeColumn, removeColumnByKey, removeColumnLayer, removeColumns, removeFooterRow, removeHeaderRow, removeThemeVariants, scheduleScrollExecution, scrollToColumn, scrollToColumn, scrollToEnd, scrollToIndex, scrollToStart, select, setAllRowsVisible, setAriaLabel, setColumnKey, setColumnOrder, setColumnOrder, setColumnRendering, setColumnReorderingAllowed, setDataProvider, setDefaultMultiSortPriority, setDetailsVisible, setDetailsVisibleOnClick, setDragDataGenerator, setDragFilter, setDropFilter, setDropMode, setEmptyStateComponent, setEmptyStateText, setItemDetailsRenderer, setItems, setItems, setItems, setItems, setItemSelectableProvider, setItemsPageable, setItemsPageable, setMultiSort, setMultiSort, setMultiSort, setMultiSort, setNestedNullBehavior, setPageSize, setPartNameGenerator, setRowsDraggable, setSelectionDragDetails, setSelectionMode, setSelectionModel, setSelectionPreservationMode, setSortableColumns, setTooltipGenerator, setTooltipMarkdownEnabled, setTooltipPosition, setUniqueKeyProperty, setUniqueKeyProvider, sort, updateSelectionModeOnClientMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisibleMethods inherited from class 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 FluentAttachNotifier
withAttachListenerMethods inherited from interface FluentBlurNotifier
withBlurListenerMethods inherited from interface FluentComponent
navigate, setId, setVisible, withId, withVisibleMethods inherited from interface FluentDetachNotifier
withDetachListenerMethods inherited from interface FluentFocusable
withTabIndexMethods inherited from interface FluentFocusNotifier
withFocusListenerMethods inherited from interface FluentHasSize
addResizeListener, withFullHeight, withFullWidth, withHeight, withMaxHeight, withMaxSize, withMaxWidth, withMinHeight, withMinSize, withMinWidth, withSize, withSizeFull, withSizeUndefined, withWidthMethods inherited from interface FluentHasStyle
getStyle, withAddedClassName, withClassName, withStyleMethods inherited from interface FluentHasTheme
withThemeNamesMethods 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.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.data.provider.HasLazyDataView
setItems, setItemsMethods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems, setItemsMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, 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, bindClassName, bindClassNames, getClassName, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
Constructor Details
-
VGrid
public VGrid() -
VGrid
public VGrid(int pageSize) -
VGrid
-
VGrid
-
-
Method Details
-
getBeanPropertyDefinitions
protected List<tools.jackson.databind.introspect.BeanPropertyDefinition> getBeanPropertyDefinitions() -
getBeanPropertyNames
-
focus
public void focus()- Specified by:
focusin interfacecom.vaadin.flow.component.Focusable<T>
-
getDefaultColumnFactory
protected BiFunction<com.vaadin.flow.data.renderer.Renderer<T>, String, com.vaadin.flow.component.grid.Grid.Column<T>> getDefaultColumnFactory()- Overrides:
getDefaultColumnFactoryin classcom.vaadin.flow.component.grid.Grid<T>
-
withSelectionMode
-
withSelectionModel
-
withProperties
-
withProperties
Configures the columns shown by the grid, using method references to the getters instead of property name strings:grid.withProperties(Person::getFirstName, Person::getLastName);- Parameters:
properties- method references to the getters of the properties to show- Returns:
- the grid for further configuration
-
hideProperties
-
hideProperties
Hides given columns, using method references to the getters instead of property name strings.- Parameters:
propertiesToHide- method references to the getters of the properties to hide- Returns:
- the grid for further configuration
-
setColumns
Configures the columns shown by the grid, using method references to the getters instead of property name strings:
Nested properties can be referenced by chaining:grid.setColumns(Person::getFirstName, Person::getLastName);grid.setColumns(PropertyRef.of(Person::getAddress).then(Address::getStreet));- Parameters:
properties- method references to the getters of the properties to show
-
addPropertyColumn
Adds a column for the given property, using a method reference to its getter instead of a property name string:grid.addPropertyColumn(Person::getFirstName).setHeader("Etunimi");- Parameters:
property- a method reference to the getter of the property to show- Returns:
- the new column, for further configuration
-
setComponentRenderer
public <C extends com.vaadin.flow.component.Component> VGrid<T> setComponentRenderer(PropertyRef<T, ?> property, com.vaadin.flow.function.ValueProvider<T, C> componentProvider) Replaces the way the column of the given property is rendered, leaving everything else about the column as it is: its position among the other columns, its key, header, width and sorting all stay put. Handy for taking an otherwise standard grid and giving just one of its columns a hand-written presentation.
Note that the column keeps the comparator it was created with, so in memory sorting keeps working on the underlying property value even though the cell now shows a component.VGrid<Person> grid = new VGrid<>(Person.class); grid.setComponentRenderer(Person::getEmail, person -> new Anchor("mailto:" + person.getEmail(), person.getEmail()));- Type Parameters:
C- the component type- Parameters:
property- a method reference to the getter of the property whose column to re-rendercomponentProvider- creates the component to show for a row- Returns:
- the grid for further configuration
- Throws:
IllegalArgumentException- if this grid has no column for the property
-
setComponentRenderer
public <C extends com.vaadin.flow.component.Component> VGrid<T> setComponentRenderer(String columnKey, com.vaadin.flow.function.ValueProvider<T, C> componentProvider) Replaces the way the column with the given key is rendered, leaving everything else about the column as it is.- Type Parameters:
C- the component type- Parameters:
columnKey- the key of the column to re-rendercomponentProvider- creates the component to show for a row- Returns:
- the grid for further configuration
- Throws:
IllegalArgumentException- if this grid has no column with the key- See Also:
-
setRenderer
public VGrid<T> setRenderer(PropertyRef<T, ?> property, com.vaadin.flow.data.renderer.Renderer<T> renderer) Replaces the renderer of the column of the given property, leaving everything else about the column as it is. The general form ofsetComponentRenderer(PropertyRef, ValueProvider), for cases where aLitRendereror one of the built-in renderers is a better fit than a server side component.- Parameters:
property- a method reference to the getter of the property whose column to re-renderrenderer- the new renderer- Returns:
- the grid for further configuration
- Throws:
IllegalArgumentException- if this grid has no column for the property
-
setRenderer
Replaces the renderer of the column with the given key, leaving everything else about the column as it is.- Parameters:
columnKey- the key of the column to re-renderrenderer- the new renderer- Returns:
- the grid for further configuration
- Throws:
IllegalArgumentException- if this grid has no column with the key- See Also:
-
addColumns
Adds columns for the given properties, using method references to their getters instead of property name strings.- Parameters:
properties- method references to the getters of the properties to show
-
setSortableColumns
Makes the columns of the given properties sortable, using method references to their getters instead of property name strings.- Parameters:
properties- method references to the getters of the properties to make sortable
-
setColumnOrder
Sets the order of the columns, using method references to the getters instead of property name strings. Note that all columns of the grid must be listed.- Parameters:
properties- method references to the getters of the properties, in the wanted order- Throws:
IllegalArgumentException- if any of the properties has no column in this grid
-
getColumnByKey
Finds the column of the given property, using a method reference to its getter instead of a property name string.- Parameters:
property- a method reference to the getter of the property- Returns:
- the column, or null if this grid has no column for the property
-
removeColumnByKey
Removes the column of the given property, using a method reference to its getter instead of a property name string.- Parameters:
property- a method reference to the getter of the property
-
setColumns
-
addColumn
-
withThemeVariants
-
setDataProvider
-
withItems
-
withItems
-
scrollToItem
Deprecated.Note, with lazy loaded content, calling this method may cause performance issuesScrolls to the row presenting the given item.- Overrides:
scrollToItemin classcom.vaadin.flow.component.grid.Grid<T>- Parameters:
item- the item to scroll to
-
withColumnSelector
-
addColumn
-
autoConfigureFromGetterReference
protected void autoConfigureFromGetterReference(com.vaadin.flow.component.grid.Grid.Column<T> column, com.vaadin.flow.function.ValueProvider<T, ?> valueProvider) If the given value provider is a method reference to a getter, configures the column likeaddColumn(String)would: the property name becomes the column key, the property caption becomes the header and a column of aComparableproperty becomes sortable.Everything here is best effort. A value provider that can't be tied to a property, a plain lambda expression in particular, leaves the column untouched, as do a property name that is already taken by another column and a method reference that doesn't look like a getter of this grid's bean type.
- Parameters:
column- the freshly created columnvalueProvider- the value provider the column was created from
-
setAutoConfigureFromGetterReferences
public void setAutoConfigureFromGetterReferences(boolean autoConfigureFromGetterReferences) Defines whether columns added with a method reference to a getter, likegrid.addColumn(Person::getFirstName), are configured with the key, header and sortability of that property. On by default.Turn this off to get the behaviour of Vaadin's raw
Grid.addColumn(ValueProvider), where such a column has no key and no header at all.- Parameters:
autoConfigureFromGetterReferences- true to configure the columns, false to leave them bare
-
isAutoConfigureFromGetterReferences
public boolean isAutoConfigureFromGetterReferences()- Returns:
- true if getter reference columns are configured with their property's key, header and sortability
-
setAutoConfigureFromGetterReferencesByDefault
public static void setAutoConfigureFromGetterReferencesByDefault(boolean autoConfigure) Defines the default ofsetAutoConfigureFromGetterReferences(boolean)for grids created after this call. Meant as an escape hatch for an application that has a lot of grids and wants the pre 3.8 behaviour.- Parameters:
autoConfigure- true to configure the columns, false to leave them bare
-
withCellFormatter
Defines a formatter used for all basic data columns.- Parameters:
formatter- the formatter- Returns:
- the VGrid for further configuration
-
withRowStyler
Adds a strategy to style cells based on rows.- Parameters:
rowStyler- the RowStyler
-