Class FGrid
- All Implemented Interfaces:
FieldEvents.BlurNotifier,FieldEvents.FocusNotifier,ItemClickEvent.ItemClickNotifier,SelectionEvent.SelectionNotifier,SortEvent.SortNotifier,ClientConnector,FAbstractClientConnector,FSizeable,Sizeable,ComponentContainer,FAbstractComponent,HasComponents,HasComponents.ComponentAttachDetachNotifier,com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasComponents,com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.shared.HasTooltip,Serializable,Iterable<com.vaadin.flow.component.Component>
Grid is always bound to a Container.Indexed, but is not a
Container of any kind in of itself. The contents of the given
Container is displayed with the help of
Renderers.
Headers and Footers
Converters and Renderers
Each column has its own Renderer that
displays data into something that can be displayed in the browser. That data
is first converted with a Converter into something that the Renderer
can process. This can also be an implicit step - if a column has a simple
data type, like a String, no explicit assignment is needed.
Usually a renderer takes some kind of object, and converts it into a HTML-formatted string.
Grid grid = new Grid(myContainer);
Column column = grid.getColumn(STRING_DATE_PROPERTY);
column.setConverter(new StringToDateConverter());
column.setRenderer(new MyColorfulDateRenderer());
Lazy Loading
The data is accessed as it is needed by Grid and not any sooner. In other words, if the given Container is huge, but only the first few rows are displayed to the user, only those (and a few more, for caching purposes) are accessed.
Selection Modes and Models
Grid supports three selection modes (single,
multi, none), and comes bundled with one model for each of the modes. The distinction between a selection mode
and selection model is as follows: a mode essentially says whether
you can have one, many or no rows selected. The model, however, has the
behavioral details of each. A single selection model may require that the
user deselects one row before selecting another one. A variant of a
multiselect might have a configurable maximum of rows that may be selected.
And so on.
FGrid grid = new FGrid(myContainer);
// uses the bundled SingleSelectionModel class
grid.setSelectionMode(SelectionMode.SINGLE);
// changes the behavior to a custom selection model
grid.setSelectionModel(new MyTwoSelectionModel());
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn abstract base class for server-side Grid extensions.static classAn abstract base class for server-sideGrid renderers.static classA base class for SelectionModels that contains some of the logic that is reusable.static interfaceA callback interface for generating optional descriptions (tooltips) for Grid cells.static classA data class which contains information which identifies a cell in aGrid.static interfaceA callback interface for generating custom style names for Grid cells.static classA column in the grid.static classAn event that is fired when the columns are reordered.static interfaceAn event listener for column reorder events in the Grid.static classAn event that is fired when a column is resized, either programmatically or by the user.static interfaceAn event listener for column resize events in the Grid.static classAn event that is fired when a column's visibility changes.static interfaceAn event listener for column visibility change events in the Grid.static classAn event which is fired when saving the editor failsclassDefault error handler for the editorstatic interfaceError handler for the editorstatic classField factory used by default in the editor.protected static classRepresents the footer section of a Grid.static classRepresents a footer cell in Grid.static classRepresents a footer row in Grid.protected static classRepresents the header section of a Grid.static classRepresents a header cell in Grid.static classRepresents a header row in Grid.static classA default implementation of aFGrid.SelectionModel.Multistatic classA default implementation for aFGrid.SelectionModel.Nonestatic interfaceA callback interface for generating optional descriptions (tooltips) for Grid rows.static classA data class which contains information which identifies a row in aGrid.static interfaceA callback interface for generating custom style names for Grid rows.static enumSelection modes representing built-inSelectionModelsthat come bundled withGrid.static interfaceThe server-side interface that controls Grid's selection state.static classA default implementation of aFGrid.SelectionModel.Singlestatic classFGrid.StaticSection<ROWTYPE extends FGrid.StaticSection.StaticRow<?>>Abstract base class for Grid header and footer sections.Nested classes/interfaces inherited from interface com.vaadin.featurepack.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.DetachEvent, ClientConnector.DetachListenerNested classes/interfaces inherited from interface com.vaadin.featurepack.server.FAbstractClientConnector
FAbstractClientConnector.LegacyMethodEventNested classes/interfaces inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
FAbstractComponent.DataKeyNested classes/interfaces inherited from interface com.vaadin.featurepack.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener -
Field Summary
FieldsFields inherited from interface com.vaadin.featurepack.server.Sizeable
SIZE_UNDEFINED -
Constructor Summary
ConstructorsConstructorDescriptionFGrid()FGrid(Container.Indexed dataSource) FGrid(String caption, Container.Indexed dataSource) -
Method Summary
Modifier and TypeMethodDescriptionAdds a new Column to Grid.Adds a new Column to Grid.protected voidaddColumnProperty(Object propertyId, Class<?> type, Object defaultValue) voidRegisters a new column reorder listener.voidRegisters a new column resize listener.voidRegisters a new column visibility change listeneraddFooterRowAt(int index) Inserts a new row at the given position to the footer section.addHeaderRowAt(int index) Inserts a new row at the given position to the header section.voidRegister a listener to handleItemClickEvents.Adds a row to the underlying container.voidRegisters a new selection listenervoidaddSortListener(SortEvent.SortListener listener) Adds a sort order change listener that gets notified when the sort order changes.Adds a new row at the bottom of the footer section.Adds a new row at the bottom of the header section.voidCancels the currently active edit if any.voidClear the current sort order, and re-sort the grid.booleanMarks an item as unselected.booleanMarks all items as unselected.protected voidprotected voidvoidOpens the editor interface for the provided item.voidfireSelectionEvent(Collection<Object> oldSelection, Collection<Object> newSelection) Fires a selection change event.Gets the content mode used for cell descriptions.Returns theCellDescriptionGeneratorinstance used to generate descriptions (tooltips) for Grid cells.Gets the style generator that is used for generating styles for cellsReturns a column based on the property idReturns a copy of currently configures columns in their current visual order in this Grid.intGets the number of children thisComponentContainerhasReturns the grid data source.Returns the current default row of the header section.Gets the id of the item that is currently being edited.Gets the current caption of the cancel button in the Grid editor.Gets the error handler used for the editorGets the field factory for theFieldGroup.Gets the field group that is backing the item editor of this grid.Gets the current caption of the save button in the Grid editor.com.vaadin.flow.component.grid.Grid<Item> Returns the internal Flow Grid instance.protected FGrid.FooterReturns the footer section of this grid.getFooterRow(int rowIndex) Gets the footer row at given index.intGets the row count for the footer.intGets the number of frozen columns in this grid. 0 means that no data columns will be frozen, but the built-in selection checkbox column will still be frozen if it's in use. -1 means that not even the selection column is frozen.protected FGrid.HeaderReturns the header section of this grid.getHeaderRow(int rowIndex) Gets the header row at given index.intGets the row count for the header section.doubleGets the amount of rows in Grid's body that are shown, whilegetHeightMode()isHeightMode.ROW.Returns the currentHeightModethe Grid is in.Gets the content mode used for row descriptions.Returns theRowDescriptionGeneratorinstance used to generate descriptions (tooltips) for Grid rowsGets the style generator that is used for generating styles for rowsGets the item id of the currently selected item.Returns a collection of all the currently selected itemIds.Returns the currently usedFGrid.SelectionModel.Get the current sort order list.protected voidbooleanReturns whether column reordering is allowed.booleanisDetailsVisible(Object itemId) Checks whether details are visible for the given item.booleanReturns whether an item is currently being edited in the editor.booleanGets the buffered editor mode.booleanChecks whether the item editor UI is enabled for this grid.booleanReturns the visibility of the footer section.booleanReturns the visibility of the header section.booleanisSelected(Object itemId) Checks whether an item is selected or not.Iterator<com.vaadin.flow.component.Component> iterator()Gets the component container iterator for going through all the components in the container.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) Adds a new row at the top of the footer section.Adds a new row at the top of the header section.voidRequests that the column widths should be recalculated.voidRefreshes, i.e. causes the client side to re-render all rows.voidrefreshRows(Object... itemIds) Refreshes, i.e. causes the client side to re-render the rows with the given item ids.voidRemoves all columns from this Grid.voidremoveColumn(Object propertyId) Removes a column from Grid based on a property id.voidRemoves a previously registered column reorder listener.voidRemoves a previously registered column resize listener.voidRemoves a previously registered column visibility change listenervoidremoveFooterRow(int rowIndex) Removes the row at the given position from the footer section.voidRemoves the given row from the footer section.voidremoveHeaderRow(int rowIndex) Removes the row at the given position from the header section.voidRemoves the given row from the header section.voidRemoves an ItemClickListener.voidRemoves a previously registered selection change listenervoidremoveSortListener(SortEvent.SortListener listener) Removes a sort order change listener previously added usingaddSortListener(SortEvent.SortListener).voidreplaceComponent(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent) Replaces the component in the container with another one without changing position.voidSaves all changes done to the bound fields.voidScrolls to a certain item, usingScrollDestination.ANY.voidScrolls to the end of the last data row.voidScrolls to the beginning of the first data row.booleanMarks an item as selected.voidSets theCellDescriptionGeneratorinstance for generating optional descriptions (tooltips) for individual Grid cells.voidsetCellDescriptionGenerator(FGrid.CellDescriptionGenerator generator, ContentMode contentMode) Sets theCellDescriptionGeneratorinstance and content mode for generating optional descriptions (tooltips) for individual Grid cells.voidsetCellStyleGenerator(FGrid.CellStyleGenerator cellStyleGenerator) Sets the style generator that is used for generating styles for cells.voidsetColumnOrder(Object... propertyIds) Sets a new column order for the grid.voidsetColumnReorderingAllowed(boolean columnReorderingAllowed) Sets whether or not column reordering is allowed.voidsetColumns(Object... propertyIds) Sets the columns and their order for the grid.voidsetContainerDataSource(Container.Indexed container) Sets the grid data source.voidSets the default row of the header.voidsetDetailsVisible(Object itemId, boolean visible) Shows or hides the details for a specific item.voidsetEditorBuffered(boolean editorBuffered) Sets the buffered editor mode.voidsetEditorCancelCaption(String cancelCaption) Sets the caption on the cancel button in the Grid editor.voidsetEditorEnabled(boolean isEnabled) Sets whether or not the item editor UI is enabled for this grid.voidsetEditorErrorHandler(FGrid.EditorErrorHandler editorErrorHandler) Sets the error handler for the editor.voidsetEditorFieldFactory(FieldGroupFieldFactory fieldFactory) Sets the field factory for theFieldGroup.voidsetEditorFieldGroup(FieldGroup fieldGroup) Sets the field group that is backing the item editor of this grid.voidsetEditorSaveCaption(String saveCaption) Sets the caption on the save button in the Grid editor.voidsetFooterVisible(boolean visible) Sets the visibility of the footer section.voidsetFrozenColumnCount(int numberOfColumns) Sets the number of frozen columns in this grid.voidsetHeaderVisible(boolean visible) Sets the visibility of the header section.voidsetHeight(float height, com.vaadin.flow.component.Unit unit) Sets the height of the object.voidSets the height of the component using String presentation.voidsetHeightByRows(double rows) Sets the number of rows that should be visible in Grid's body, whilegetHeightMode()isHeightMode.ROW.voidsetHeightMode(HeightMode heightMode) Defines the mode in which the Grid widget's height is calculated.voidsetLabelComponent(com.vaadin.flow.component.Component labelComponent) Sets the component's label component.voidSets theRowDescriptionGeneratorinstance for generating optional descriptions (tooltips) for Grid rows.voidsetRowDescriptionGenerator(FGrid.RowDescriptionGenerator generator, ContentMode contentMode) Sets theRowDescriptionGeneratorinstance for generating optional descriptions (tooltips) for Grid rows.voidsetRowStyleGenerator(FGrid.RowStyleGenerator rowStyleGenerator) Sets the style generator that is used for generating styles for rows.setSelectionMode(FGrid.SelectionMode selectionMode) Sets the Grid's selection mode.voidsetSelectionModel(FGrid.SelectionModel selectionModel) Takes a newFGrid.SelectionModelinto use.voidsetSortOrder(List<SortOrder> order) Sets the sort order to use.voidSets the current sort order using the fluid Sort API.voidSort this Grid in ascending order by a specified property.voidsort(Object propertyId, SortDirection direction) Sort this Grid in user-specifiedSortOrderby a property.Methods inherited from class com.vaadin.featurepack.ui.AbstractComponentContainer
add, addComponent, addComponentAttachListener, addComponentDetachListener, addComponents, fireComponentAttachEvent, fireComponentDetachEvent, moveComponentsFrom, remove, removeAll, removeAllComponents, removeComponent, setWidthMethods inherited from class com.vaadin.featurepack.ui.AbstractComponent
addClassName, addClassNames, addInternalStyles, beforeClientResponse, doSetHeight, doSetWidth, fireComponentEvent, fireEvent, focus, getClassName, getClassNames, getCustomStyles, getHeight, getHeightUnits, getInternalStyles, getLocale, getStyle, getTooltip, getWidth, getWidthUnits, hasClassName, isOrHasAncestor, isVisible, onEnabledStateChanged, removeClassName, removeClassNames, removeInternalStyles, setClassName, setClassName, setHeightFull, setHeightUndefined, setParent, setSizeFull, setSizeUndefined, setTooltipText, setVisible, setWidth, setWidthFull, setWidthUndefinedMethods inherited from class com.vaadin.featurepack.server.AbstractClientConnector
getSessionMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, findAncestor, from, get, getChildren, getElement, getEventBus, getId, getListeners, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, whenAttachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.featurepack.server.FAbstractClientConnector
addLegacyAttachListener, addLegacyDetachListener, addListener, addListener, attach, detach, doConnectorOnAttach, doConnectorOnDetach, fireEvent, fireEvent, getAllChildrenIterable, getFListeners, getFlowComponent, getResource, hasListeners, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeListener, removeListener, setResourceMethods inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, addStyleNames, beforeClientResponse, getCaption, getComponentError, getData, getDescription, getFErrorIndicator, getFErrorMessage, getFId, getFParent, getIcon, getIconResource, getPrimaryStyleName, getStyleName, isCaptionAsHtml, isImmediate, isResponsive, notifyParentAboutStyleChanges, removeContextClickListener, removeShortcutListener, removeStyleName, removeStyleNames, setCaption, setCaptionAsHtml, setComponentError, setData, setDescription, setDescription, setIcon, setIcon, setIconResource, setImmediate, setLocale, setPrimaryStyleName, setResponsive, setStyleName, setStyleNameMethods inherited from interface com.vaadin.featurepack.event.FieldEvents.BlurNotifier
addBlurListener, removeBlurListenerMethods inherited from interface com.vaadin.featurepack.event.FieldEvents.FocusNotifier
addFocusListener, removeFocusListenerMethods inherited from interface com.vaadin.featurepack.server.FSizeable
getFHeight, getFWidth, getHeightUnits, getWidthUnits, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefinedMethods inherited from interface com.vaadin.flow.component.HasComponents
addMethods inherited from interface com.vaadin.flow.component.HasComponentsOfType
add, addComponentAsFirst, addComponentAtIndex, bindChildren, getChildren, getComponentAt, indexOf, remove, replaceMethods 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.component.HasLabel
getLabel, setLabelMethods inherited from interface com.vaadin.flow.component.HasStyle
bindClassName, bindClassNamesMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
setTooltipMarkdownMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
cellTooltipContentMode
-
-
Constructor Details
-
FGrid
public FGrid() -
FGrid
-
FGrid
-
FGrid
-
-
Method Details
-
handleError
-
getFlowGrid
Returns the internal Flow Grid instance.- Returns:
- the Flow Grid instance
-
setLabelComponent
public void setLabelComponent(com.vaadin.flow.component.Component labelComponent) Description copied from interface:FAbstractComponentSets the component's label component. Flow components that support caption component usually overrides this.- Specified by:
setLabelComponentin interfaceFAbstractComponent- Parameters:
labelComponent- the new label component for the component.
-
getContainerDataSource
Returns the grid data source.- Returns:
- the container data source of the grid
-
setContainerDataSource
Sets the grid data source.Note Grid columns are based on properties and try to detect a correct converter for the data type. The columns are not reinitialized automatically if the container is changed, and if the same properties are present after container change, the columns are reused. Properties with same names, but different data types will lead to unpredictable behaviour.
- Parameters:
container- The container data source. Cannot be null.- Throws:
IllegalArgumentException- if the data source is null
-
replaceComponent
public void replaceComponent(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent) Description copied from interface:ComponentContainerReplaces the component in the container with another one without changing position.This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.
- Specified by:
replaceComponentin interfaceComponentContainer- Parameters:
oldComponent- the old component that will be replaced.newComponent- the new component to be replaced.
-
getComponentCount
public int getComponentCount()Description copied from interface:ComponentContainerGets the number of children thisComponentContainerhas- Specified by:
getComponentCountin interfaceComponentContainer- Specified by:
getComponentCountin interfacecom.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>- Returns:
- The number of child components this container has.
-
getColumn
Returns a column based on the property id- Parameters:
propertyId- the property id of the column- Returns:
- the column or
nullif not found
-
getColumns
Returns a copy of currently configures columns in their current visual order in this Grid.- Returns:
- unmodifiable copy of current columns in visual order
-
addColumn
Adds a new Column to Grid. Also adds the property to container with data type String, if property for column does not exist in it. Default value for the new property is an empty String.Note that adding a new property is only done for the default container that Grid sets up with the default constructor.
- Parameters:
propertyId- the property id of the new column- Returns:
- the new column
- Throws:
IllegalStateException- if column for given property already exists in this grid
-
addColumn
Adds a new Column to Grid. This function makes sure that the property with the given id and data type exists in the container. If property does not exists, it will be created.Default value for the new property is 0 if type is Integer, Double and Float. If type is String, default value is an empty string. For all other types the default value is null.
Note that adding a new property is only done for the default container that Grid sets up with the default constructor.
- Parameters:
propertyId- the property id of the new columntype- the data type for the new property- Returns:
- the new column
- Throws:
IllegalStateException- if column for given property already exists in this grid or property already exists in the container with wrong type
-
removeAllColumns
public void removeAllColumns()Removes all columns from this Grid. -
removeColumn
Removes a column from Grid based on a property id.- Parameters:
propertyId- The property id of column to be removed- Throws:
IllegalArgumentException- if there is no column for given property id in this grid
-
isColumnReorderingAllowed
public boolean isColumnReorderingAllowed()Returns whether column reordering is allowed. Default value isfalse.- Returns:
- true if reordering is allowed
-
setColumnReorderingAllowed
public void setColumnReorderingAllowed(boolean columnReorderingAllowed) Sets whether or not column reordering is allowed. Default value isfalse.- Parameters:
columnReorderingAllowed- specifies whether column reordering is allowed
-
setColumns
Sets the columns and their order for the grid. Current columns whose property id is not in propertyIds are removed. Similarly, a column is added for any property id in propertyIds that has no corresponding column in this Grid.- Parameters:
propertyIds- properties in the desired column order
-
setColumnOrder
Sets a new column order for the grid. All columns which are not ordered here will remain in the order they were before as the last columns of grid.- Parameters:
propertyIds- properties in the order columns should be
-
setFrozenColumnCount
public void setFrozenColumnCount(int numberOfColumns) Sets the number of frozen columns in this grid. Setting the count to 0 means that no data columns will be frozen, but the built-in selection checkbox column will still be frozen if it's in use. Setting the count to -1 will also disable the selection column.The default value is 0.
- Parameters:
numberOfColumns- the number of columns that should be frozen- Throws:
IllegalArgumentException- if the column count is invalid input: '<' 0 or > the number of visible columns
-
getFrozenColumnCount
public int getFrozenColumnCount()Gets the number of frozen columns in this grid. 0 means that no data columns will be frozen, but the built-in selection checkbox column will still be frozen if it's in use. -1 means that not even the selection column is frozen.NOTE: this count includes
hidden columnsin the count.- Returns:
- the number of frozen columns
- See Also:
-
scrollTo
Scrolls to a certain item, usingScrollDestination.ANY.- Parameters:
itemId- id of item to scroll to.- Throws:
IllegalArgumentException- if the provided id is not recognized by the data source.
-
scrollToStart
public void scrollToStart()Scrolls to the beginning of the first data row. -
scrollToEnd
public void scrollToEnd()Scrolls to the end of the last data row. -
setHeightByRows
public void setHeightByRows(double rows) Sets the number of rows that should be visible in Grid's body, whilegetHeightMode()isHeightMode.ROW.If Grid is currently not in
HeightMode.ROW, the given value is remembered, and applied once the mode is applied.- Parameters:
rows- The height in terms of number of rows displayed in Grid's body. If Grid doesn't contain enough rows, white space is displayed instead. Ifnullis given, then Grid's height is undefined- Throws:
IllegalArgumentException- ifrowsis zero or lessIllegalArgumentException- ifrowsisinfiniteIllegalArgumentException- ifrowsisNaN
-
getHeightByRows
public double getHeightByRows()Gets the amount of rows in Grid's body that are shown, whilegetHeightMode()isHeightMode.ROW.- Returns:
- the amount of rows that are being shown in Grid's body
- See Also:
-
setHeight
Description copied from interface:SizeableSets the height of the component using String presentation.String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size.
The empty string ("") or null will unset the height and set the units to pixels.
See CSS specification for more details.
-
setHeight
public void setHeight(float height, com.vaadin.flow.component.Unit unit) Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).Note: This method will change the widget's size in the browser only if
getHeightMode()returnsHeightMode.CSS. -
getHeightMode
Returns the currentHeightModethe Grid is in.Defaults to
HeightMode.CSS.- Returns:
- the current HeightMode
-
setSelectionModel
Takes a newFGrid.SelectionModelinto use.The SelectionModel that is previously in use will have all its items deselected. If any items were selected, this will fire a
SelectionEvent.If the given SelectionModel is already in use, this method does nothing.
- Parameters:
selectionModel- the new SelectionModel to use- Throws:
IllegalArgumentException- ifselectionModelisnull
-
getSelectionModel
Returns the currently usedFGrid.SelectionModel.- Returns:
- the currently used SelectionModel
-
setSelectionMode
public FGrid.SelectionModel setSelectionMode(FGrid.SelectionMode selectionMode) throws IllegalArgumentException Sets the Grid's selection mode.Grid supports three selection modes: multiselect, single select and no selection, and this is a convenience method for choosing between one of them.
Technically, this method is a shortcut that can be used instead of calling
setSelectionModelwith a specific SelectionModel instance. Grid comes with three built-in SelectionModel classes, and theGrid.SelectionModeenum represents each of them.Essentially, the two following method calls are equivalent:
grid.setSelectionMode(SelectionMode.MULTI); grid.setSelectionModel(new MultiSelectionMode());
- Parameters:
selectionMode- the selection mode to switch to- Returns:
- The
FGrid.SelectionModelinstance that was taken into use - Throws:
IllegalArgumentException- ifselectionModeisnull- See Also:
-
isSelected
Checks whether an item is selected or not.- Parameters:
itemId- the item id to check for- Returns:
trueiff the item is selected
-
getSelectedRows
Returns a collection of all the currently selected itemIds.This method is a shorthand that delegates to the
selection model.- Returns:
- a collection of all the currently selected itemIds
-
getSelectedRow
Gets the item id of the currently selected item.This method is a shorthand that delegates to the
selection model. OnlyFGrid.SelectionModel.Singleis supported.- Returns:
- the item id of the currently selected item, or
nullif nothing is selected - Throws:
IllegalStateException- if the selection model does not implementSelectionModel.Single
-
select
Marks an item as selected.This method is a shorthand that delegates to the
selection model. OnlyFGrid.SelectionModel.SingleandFGrid.SelectionModel.Multiare supported.- Parameters:
itemId- the itemId to mark as selected- Returns:
trueif the selection state changed,falseif the itemId already was selected- Throws:
IllegalArgumentException- if theitemIddoesn't exist in the currently active ContainerIllegalStateException- if the selection was illegal. One such reason might be that the implementation already had an item selected, and that needs to be explicitly deselected before re-selecting something.IllegalStateException- if the selection model does not implementSelectionModel.SingleorSelectionModel.Multi
-
deselect
Marks an item as unselected.This method is a shorthand that delegates to the
selection model. OnlyFGrid.SelectionModel.SingleandFGrid.SelectionModel.Multiare supported.- Parameters:
itemId- the itemId to remove from being selected- Returns:
trueif the selection state changed,falseif the itemId was already selected- Throws:
IllegalArgumentException- if theitemIddoesn't exist in the currently active ContainerIllegalStateException- if the deselection was illegal. One such reason might be that the implementation requires one or more items to be selected at all times.IllegalStateException- if the selection model does not implementSelectionModel.Singleor {code SelectionModel.Multi}
-
deselectAll
Marks all items as unselected.This method is a shorthand that delegates to the
selection model. OnlyFGrid.SelectionModel.SingleandFGrid.SelectionModel.Multiare supported.- Returns:
trueif the selection state changed,falseif the itemId was already selected- Throws:
IllegalStateException- if the deselection was illegal. One such reason might be that the implementation requires one or more items to be selected at all times.IllegalStateException- if the selection model does not implementSelectionModel.Singleor {code SelectionModel.Multi}
-
fireSelectionEvent
Fires a selection change event.Note: This is not a method that should be called by application logic. This method is publicly accessible only so that
SelectionModelswould be able to inform Grid of these events.- Parameters:
oldSelection- the selection that was removed by this eventnewSelection- the selection that was added by this event
-
addSelectionListener
Description copied from interface:SelectionEvent.SelectionNotifierRegisters a new selection listener- Specified by:
addSelectionListenerin interfaceSelectionEvent.SelectionNotifier- Parameters:
listener- the listener to register
-
removeSelectionListener
Description copied from interface:SelectionEvent.SelectionNotifierRemoves a previously registered selection change listener- Specified by:
removeSelectionListenerin interfaceSelectionEvent.SelectionNotifier- Parameters:
listener- the listener to remove
-
addColumnReorderListener
Registers a new column reorder listener.- Parameters:
listener- the listener to register
-
removeColumnReorderListener
Removes a previously registered column reorder listener.- Parameters:
listener- the listener to remove
-
addColumnResizeListener
Registers a new column resize listener.- Parameters:
listener- the listener to register
-
removeColumnResizeListener
Removes a previously registered column resize listener.- Parameters:
listener- the listener to remove
-
sort
Sets the current sort order using the fluid Sort API. Read the documentation forSortfor more information.Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
- Parameters:
s- a sort instance- Throws:
IllegalStateException- if container is not sortable (does not implement Container.Sortable)IllegalArgumentException- if trying to sort by non-existing property
-
sort
Sort this Grid in ascending order by a specified property.Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
- Parameters:
propertyId- a property ID- Throws:
IllegalStateException- if container is not sortable (does not implement Container.Sortable)IllegalArgumentException- if trying to sort by non-existing property
-
sort
Sort this Grid in user-specifiedSortOrderby a property.Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
- Parameters:
propertyId- a property IDdirection- a sort order value (ascending/descending)- Throws:
IllegalStateException- if container is not sortable (does not implement Container.Sortable)IllegalArgumentException- if trying to sort by non-existing property
-
clearSortOrder
public void clearSortOrder()Clear the current sort order, and re-sort the grid. -
setSortOrder
Sets the sort order to use.Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
- Parameters:
order- a sort order list.- Throws:
IllegalStateException- if container is not sortable (does not implement Container.Sortable)IllegalArgumentException- if order is null or trying to sort by non-existing property
-
getSortOrder
Get the current sort order list.- Returns:
- a sort order list
-
addSortListener
Adds a sort order change listener that gets notified when the sort order changes.- Specified by:
addSortListenerin interfaceSortEvent.SortNotifier- Parameters:
listener- the sort order change listener to add
-
removeSortListener
Removes a sort order change listener previously added usingaddSortListener(SortEvent.SortListener).- Specified by:
removeSortListenerin interfaceSortEvent.SortNotifier- Parameters:
listener- the sort order change listener to remove
-
getHeader
Returns the header section of this grid. The default header contains a single row displaying the column captions.- Returns:
- the header
-
getHeaderRow
Gets the header row at given index.- Parameters:
rowIndex- 0 based index for row. Counted from top to bottom- Returns:
- header row at given index
- Throws:
IllegalArgumentException- if no row exists at given index
-
addHeaderRowAt
Inserts a new row at the given position to the header section. Shifts the row currently at that position and any subsequent rows down (adds one to their indices).- Parameters:
index- the position at which to insert the row- Returns:
- the new row
- Throws:
IllegalArgumentException- if the index is less than 0 or greater than row count- See Also:
-
appendHeaderRow
Adds a new row at the bottom of the header section.- Returns:
- the new row
- See Also:
-
getDefaultHeaderRow
Returns the current default row of the header section. The default row is a special header row providing a user interface for sorting columns. Setting a header text for column updates cells in the default header. Feature Pack's default header row has limitations compared to Vaadin 7 API. If row is the default row for Flow's Grid header, it doesn't allow joining cells together.- Returns:
- the default row or null if no default row set
-
getHeaderRowCount
public int getHeaderRowCount()Gets the row count for the header section.- Returns:
- row count
-
prependHeaderRow
Adds a new row at the top of the header section.- Returns:
- the new row
- See Also:
-
removeHeaderRow
Removes the given row from the header section.- Parameters:
row- the row to be removed- Throws:
IllegalArgumentException- if the row does not exist in this section- See Also:
-
removeHeaderRow
public void removeHeaderRow(int rowIndex) Removes the row at the given position from the header section.- Parameters:
rowIndex- the position of the row- Throws:
IllegalArgumentException- if no row exists at given index- See Also:
-
setDefaultHeaderRow
Sets the default row of the header. The default row is a special header row providing a user interface for sorting columns.- Parameters:
row- the new default row, or null for no default row- Throws:
IllegalArgumentException- header does not contain the row
-
setHeaderVisible
public void setHeaderVisible(boolean visible) Sets the visibility of the header section.- Parameters:
visible- true to show header section, false to hide
-
isHeaderVisible
public boolean isHeaderVisible()Returns the visibility of the header section.- Returns:
- true if visible, false otherwise.
-
iterator
Description copied from class:AbstractComponentContainerGets the component container iterator for going through all the components in the container.- Specified by:
iteratorin interfaceHasComponents- Specified by:
iteratorin interfaceIterable<com.vaadin.flow.component.Component>- Overrides:
iteratorin classAbstractComponentContainer- Returns:
- the Iterator of the components inside the container.
-
setCellDescriptionGenerator
Sets theCellDescriptionGeneratorinstance for generating optional descriptions (tooltips) for individual Grid cells. If aFGrid.RowDescriptionGeneratoris also set, the row description it generates is displayed for cells for whichgeneratorreturnsnull.The descriptions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used.
- Parameters:
generator- the description generator to use ornullto remove a previously set generator if any- See Also:
-
getCellDescriptionGenerator
Returns theCellDescriptionGeneratorinstance used to generate descriptions (tooltips) for Grid cells.- Returns:
- the description generator or
nullif no generator is set
-
getCellDescriptionContentMode
Gets the content mode used for cell descriptions.- Returns:
- the content mode used for cell descriptions, not
null - See Also:
-
setRowDescriptionGenerator
Sets theRowDescriptionGeneratorinstance for generating optional descriptions (tooltips) for Grid rows. If aFGrid.CellDescriptionGeneratoris also set, the row description generated bygeneratoris used for cells for which the cell description generator returnsnull.The descriptions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used.
- Parameters:
generator- the description generator to use ornullto remove a previously set generator if any- See Also:
-
getRowDescriptionContentMode
Gets the content mode used for row descriptions.- Returns:
- the content mode used for row descriptions, not
null - See Also:
-
getRowDescriptionGenerator
Returns theRowDescriptionGeneratorinstance used to generate descriptions (tooltips) for Grid rows- Returns:
- the description generator or null if no generator is set
-
setCellStyleGenerator
Sets the style generator that is used for generating styles for cells. Style name is set to 'part' attribute of the target cells.- Parameters:
cellStyleGenerator- the cell style generator to set, ornullto remove a previously set generator
-
getCellStyleGenerator
Gets the style generator that is used for generating styles for cells- Returns:
- the cell style generator, or
nullif no generator is set
-
setRowStyleGenerator
Sets the style generator that is used for generating styles for rows. Style name is set to 'part' attribute of the target row's cells.- Parameters:
rowStyleGenerator- the row style generator to set, ornullto remove a previously set generator
-
getRowStyleGenerator
Gets the style generator that is used for generating styles for rows- Returns:
- the row style generator, or
nullif no generator is set
-
addRow
Adds a row to the underlying container. The order of the parameters should match the current visible column order.Please note that it's generally only safe to use this method during initialization. After Grid has been initialized and the visible column order might have been changed, it's better to instead add items directly to the underlying container and use
Item.getItemProperty(Object)to make sure each value is assigned to the intended property.- Parameters:
values- the cell values of the new row, in the same order as the visible column order, notnull.- Returns:
- the item id of the new row
- Throws:
IllegalArgumentException- if values is nullIllegalArgumentException- if its length does not match the number of visible columnsIllegalArgumentException- if a parameter value is not an instance of the corresponding property typeUnsupportedOperationException- if the container does not support adding new items
-
refreshRows
Refreshes, i.e. causes the client side to re-render the rows with the given item ids.Calling this for a row which is not currently rendered on the client side has no effect.
- Parameters:
itemIds- the item id(s) of the row to refresh.
-
refreshAllRows
public void refreshAllRows()Refreshes, i.e. causes the client side to re-render all rows. -
setEditorEnabled
Sets whether or not the item editor UI is enabled for this grid. When the editor is enabled, the user can open it by double-clicking a row or hitting enter when a row is focused. The editor can also be opened programmatically using theeditItem(Object)method.- Parameters:
isEnabled-trueto enable the feature,falseotherwise- Throws:
IllegalStateException- if an item is currently being edited- See Also:
-
isEditorEnabled
public boolean isEditorEnabled()Checks whether the item editor UI is enabled for this grid.- Returns:
trueiff the editor is enabled for this grid- See Also:
-
getEditedItemId
Gets the id of the item that is currently being edited.- Returns:
- the id of the item that is currently being edited, or
nullif no item is being edited at the moment
-
getEditorFieldGroup
Gets the field group that is backing the item editor of this grid.- Returns:
- the backing field group
-
setEditorFieldGroup
Sets the field group that is backing the item editor of this grid.- Parameters:
fieldGroup- the backing field group- Throws:
IllegalStateException- if the editor is currently active
-
isEditorActive
public boolean isEditorActive()Returns whether an item is currently being edited in the editor.- Returns:
- true if the editor is open
-
editItem
Opens the editor interface for the provided item. Scrolls the Grid to bring the item to view if it is not already visible. Note that any cell content rendered by a WidgetRenderer will not be visible in the editor row.- Parameters:
itemId- the id of the item to edit- Throws:
IllegalStateException- if the editor is not enabled or already editing an item in buffered modeIllegalArgumentException- if theitemIdis not in the backing container- See Also:
-
doEditItem
protected void doEditItem() -
saveEditor
Saves all changes done to the bound fields.Note: This is a pass-through call to the backing field group.
- Throws:
FieldGroup.CommitException- If the commit was aborted- See Also:
-
cancelEditor
public void cancelEditor()Cancels the currently active edit if any. Hides the editor and discards possible unsaved changes in the editor fields. -
doCancelEditor
protected void doCancelEditor() -
setEditorFieldFactory
Sets the field factory for theFieldGroup. The field factory is only used whenFieldGroupcreates a new field.Note: This is a pass-through call to the backing field group.
- Parameters:
fieldFactory- The field factory to use
-
setEditorErrorHandler
public void setEditorErrorHandler(FGrid.EditorErrorHandler editorErrorHandler) throws IllegalArgumentException Sets the error handler for the editor. The error handler is called whenever there is an exception in the editor.- Parameters:
editorErrorHandler- The editor error handler to use- Throws:
IllegalArgumentException- if the error handler is null
-
getEditorErrorHandler
Gets the error handler used for the editor- Returns:
- the editor error handler, never null
-
getEditorFieldFactory
Gets the field factory for theFieldGroup. The field factory is only used whenFieldGroupcreates a new field.Note: This is a pass-through call to the backing field group.
- Returns:
- The field factory in use
-
setEditorSaveCaption
Sets the caption on the save button in the Grid editor.- Parameters:
saveCaption- the caption to set- Throws:
IllegalArgumentException- ifsaveCaptionisnull
-
getEditorSaveCaption
Gets the current caption of the save button in the Grid editor.- Returns:
- the current caption of the save button
-
setEditorCancelCaption
Sets the caption on the cancel button in the Grid editor.- Parameters:
cancelCaption- the caption to set- Throws:
IllegalArgumentException- ifcancelCaptionisnull
-
getEditorCancelCaption
Gets the current caption of the cancel button in the Grid editor.- Returns:
- the current caption of the cancel button
-
setEditorBuffered
Sets the buffered editor mode. The default mode is buffered (true).- Parameters:
editorBuffered-trueto enable buffered editor,falseto disable it- Throws:
IllegalStateException- If editor is active while attempting to change the buffered mode.
-
isEditorBuffered
public boolean isEditorBuffered()Gets the buffered editor mode.- Returns:
trueif buffered editor is enabled,falseotherwise- Since:
- 7.6
-
addItemClickListener
Description copied from interface:ItemClickEvent.ItemClickNotifierRegister a listener to handleItemClickEvents.- Specified by:
addItemClickListenerin interfaceItemClickEvent.ItemClickNotifier- Parameters:
listener- ItemClickListener to be registered
-
removeItemClickListener
Description copied from interface:ItemClickEvent.ItemClickNotifierRemoves an ItemClickListener.- Specified by:
removeItemClickListenerin interfaceItemClickEvent.ItemClickNotifier- Parameters:
listener- ItemClickListener to be removed
-
setDetailsVisible
Shows or hides the details for a specific item.- Parameters:
itemId- the id of the item for which to set details visibilityvisible-trueto show the details, orfalseto hide them
-
isDetailsVisible
Checks whether details are visible for the given item.- Parameters:
itemId- the id of the item for which to check details visibility- Returns:
trueiff the details are visible
-
recalculateColumnWidths
public void recalculateColumnWidths()Requests that the column widths should be recalculated.In most cases Grid will know when column widths need to be recalculated but this method can be used to force recalculation in situations when grid does not recalculate automatically.
-
addColumnVisibilityChangeListener
Registers a new column visibility change listener- Parameters:
listener- the listener to register
-
removeColumnVisibilityChangeListener
Removes a previously registered column visibility change listener- Parameters:
listener- the listener to remove
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classAbstractClientConnector
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
onDetachin classAbstractClientConnector
-
addColumnProperty
protected void addColumnProperty(Object propertyId, Class<?> type, Object defaultValue) throws IllegalStateException - Throws:
IllegalStateException
-