com.vaadin.ui.
Class Grid<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractListing<T>
-
- com.vaadin.ui.Grid<T>
-
Type Parameters:
T
- the grid bean typeAll Implemented Interfaces:
HasDataProvider<T>
,HasItems<T>
,ContextClickEvent.ContextClickNotifier
,MethodEventSource
,SortEvent.SortNotifier<GridSortOrder<T>>
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,HasComponents
,Serializable
,Iterable<Component>
Direct Known Subclasses:
public class Grid<T> extends AbstractListing<T> implements HasComponents, HasDataProvider<T>, SortEvent.SortNotifier<GridSortOrder<T>>
A grid component for displaying tabular data.
Since:
8.0
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Grid.AbstractGridExtension<T>
A helper base class for creating extensions for the Grid component.
static class
Grid.Column<T,V>
This extension manages the configuration and data communication for a Column inside of a Grid component.
static class
Grid.ColumnReorderEvent
An event that is fired when the columns are reordered.
static class
Grid.ColumnResizeEvent
An event that is fired when a column is resized, either programmatically or by the user.
static class
Grid.ColumnVisibilityChangeEvent
An event that is fired when a column's visibility changes.
static class
Grid.DetailsManager<T>
Class for managing visible details rows.
static interface
Grid.FetchItemsCallback<T>
A callback method for fetching items.
static class
Grid.GridContextClickEvent<T>
ContextClickEvent for the Grid Component.
static class
Grid.ItemClick<T>
An event fired when an item in the Grid has been clicked.
static class
Grid.SelectionMode
Selection mode representing the built-in selection models in grid.
-
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractListing
AbstractListing.AbstractListingExtension<T>
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
-
-
Constructor Summary
Constructors Modifier Constructor Description Grid()
Creates a new grid without support for creating columns based on property names.
protected
Grid(PropertySet<T> propertySet)
Creates a grid using a custom
PropertySet
implementation for configuring the initial columns and resolving property names foraddColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.protected
Grid(PropertySet<T> propertySet, DataCommunicator<T> dataCommunicator)
Creates a grid using a custom
PropertySet
implementation and custom data communicator.protected
Grid(DataCommunicator<T> dataCommunicator)
Creates a new grid with the given data communicator and without support for creating columns based on property names.
Grid(DataProvider<T,?> dataProvider)
Creates a new
Grid
using the givenDataProvider
.Grid(Class<T> beanType)
Creates a new grid that uses reflection based on the provided bean type to automatically set up an initial set of columns.
protected
Grid(Class<T> beanType, DataCommunicator<T> dataCommunicator)
Creates a new grid that uses custom data communicator and provided bean type It uses reflection of the provided bean type to automatically set up an initial set of columns.
Grid(String caption)
Creates a new
Grid
using the given caption.Grid(String caption, DataProvider<T,?> dataProvider)
Creates a new
Grid
using the given caption andDataProvider
.Grid(String caption, Collection<T> items)
Creates a new
Grid
using the given caption and collection of items.
-
Method Summary
All Methods Modifier and Type Method Description <V> Grid.Column<T,V>
addColumn(ValueProvider<T,V> valueProvider)
Adds a new text column to this
Grid
with a value provider.<V> Grid.Column<T,V>
addColumn(ValueProvider<T,V> valueProvider, ValueProvider<V,String> presentationProvider)
Adds a new column to this
Grid
with value provider and presentation provider.<V,P>
Grid.Column<T,V>addColumn(ValueProvider<T,V> valueProvider, ValueProvider<V,P> presentationProvider, AbstractRenderer<? super T,? super P> renderer)
Adds a new column to this
Grid
with value provider, presentation provider and typed renderer.<V> Grid.Column<T,V>
addColumn(ValueProvider<T,V> valueProvider, AbstractRenderer<? super T,? super V> renderer)
Adds a new column to this
Grid
with typed renderer and value provider.Grid.Column<T,?>
addColumn(String propertyName)
Adds a new column with the given property name.
Grid.Column<T,?>
addColumn(String propertyName, AbstractRenderer<? super T,?> renderer)
Adds a new column with the given property name and renderer.
Grid.Column<T,?>
addColumn(String propertyName, AbstractRenderer<? super T,?> renderer, Grid.Column.NestedNullBehavior nestedNullBehavior)
Adds a new column with the given property name and renderer.
Registration
addColumnReorderListener(ColumnReorderListener listener)
Registers a new column reorder listener.
Registration
addColumnResizeListener(ColumnResizeListener listener)
Registers a new column resize listener.
Registration
addColumnVisibilityChangeListener(ColumnVisibilityChangeListener listener)
Registers a new column visibility change listener.
<V extends Component>
Grid.Column<T,V>addComponentColumn(ValueProvider<T,V> componentProvider)
Adds a column that shows components.
Registration
addContextClickListener(ContextClickEvent.ContextClickListener listener)
Adds a context click listener that gets notified when a context click happens.
FooterRow
addFooterRowAt(int index)
Inserts a new row at the given position to the footer section.
HeaderRow
addHeaderRowAt(int index)
Inserts a new row at the given position to the header section.
Registration
addItemClickListener(ItemClickListener<? super T> listener)
Adds an item click listener.
Registration
addSelectionListener(SelectionListener<T> listener)
Adds a selection listener to the current selection model.
Registration
addSortListener(SortEvent.SortListener<GridSortOrder<T>> listener)
Adds a sort order change listener that gets notified when the sort order changes.
FooterRow
appendFooterRow()
Adds a new row at the bottom of the footer section.
HeaderRow
appendHeaderRow()
Adds a new row at the bottom of the header section.
GridMultiSelect<T>
asMultiSelect()
User this grid as a multiselect in
Binder
.GridSingleSelect<T>
asSingleSelect()
Use this grid as a single select in
Binder
.void
beforeClientResponse(boolean initial)
Called before the shared state and RPC invocations are sent to the client.
void
clearSortOrder()
Clear the current sort order, and re-sort the grid.
protected <V,P>
Grid.Column<T,V>createColumn(ValueProvider<T,V> valueProvider, ValueProvider<V,P> presentationProvider, AbstractRenderer<? super T,? super P> renderer)
Creates a column instance from a value provider, presentation provider and a renderer.
protected Editor<T>
createEditor()
Creates a new Editor instance.
protected SerializableComparator<T>
createSortingComparator()
Creates a comparator for grid to sort rows.
void
deselect(T item)
This method is a shorthand that delegates to the currently set selection model.
void
deselectAll()
This method is a shorthand that delegates to the currently set selection model.
protected T
deserializeDeclarativeRepresentation(String item)
Deserializes a string to a data item.
protected void
doReadDesign(org.jsoup.nodes.Element design, DesignContext context)
Reads the listing specific state from the given design.
protected void
doWriteDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Writes listing specific state into the given design.
<V> void
fireColumnVisibilityChangeEvent(Grid.Column<T,V> column, boolean hidden, boolean userOriginated)
Sends a
Grid.ColumnVisibilityChangeEvent
to all listeners.Class<T>
getBeanType()
Gets the bean type used by this grid.
double
getBodyRowHeight()
Returns the current body row height.
Grid.Column<T,?>
getColumn(String columnId)
Gets a
Grid.Column
of this grid by its identifying string.protected Grid.Column<T,?>
getColumnByInternalId(String columnId)
Returns a column identified by its internal id.
ColumnResizeMode
getColumnResizeMode()
Returns the current column resize mode.
List<Grid.Column<T,?>>
getColumns()
Gets an unmodifiable collection of all columns currently in this
Grid
.protected Collection<String>
getCustomAttributes()
Returns a collection of attributes that should not be handled by the basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods.DataProvider<T,?>
getDataProvider()
Returns the source of data items used by this listing.
HeaderRow
getDefaultHeaderRow()
Returns the current default row of the header.
DescriptionGenerator<T>
getDescriptionGenerator()
Gets the description generator that is used for generating descriptions for rows.
Editor<T>
getEditor()
Returns the
Editor
for this grid.protected Footer
getFooter()
Returns the footer section of this grid.
FooterRow
getFooterRow(int index)
Returns the footer row at the given index.
int
getFooterRowCount()
Gets the number of rows in the footer section.
double
getFooterRowHeight()
Returns the current footer row height.
int
getFrozenColumnCount()
Gets the number of frozen columns in this grid.
protected Header
getHeader()
Returns the header section of this grid.
HeaderRow
getHeaderRow(int index)
Returns the header row at the given index.
int
getHeaderRowCount()
Gets the number of rows in the header section.
double
getHeaderRowHeight()
Returns the current header row height.
double
getHeightByRows()
Gets the amount of rows in Grid's body that are shown, while
getHeightMode()
isHeightMode.ROW
.HeightMode
getHeightMode()
Returns the current
HeightMode
the Grid is in.protected String
getInternalIdForColumn(Grid.Column<T,?> column)
Returns the internal id for given column.
protected PropertySet<T>
getPropertySet()
Returns the property set used by this grid.
double
getRowHeight()
Deprecated.
replaced by three separate row height controlsSet<T>
getSelectedItems()
This method is a shorthand that delegates to the currently set selection model.
GridSelectionModel<T>
getSelectionModel()
Returns the selection model for this grid.
GridConstants.SidebarColumnOrder
getSidebarColumnOrder()
Get the current sidebar column order.
List<GridSortOrder<T>>
getSortOrder()
Get the current sort order list.
protected GridState
getState()
Returns the shared state bean with information to be sent from the server to the client.
protected GridState
getState(boolean markAsDirty)
Returns the shared state for this connector.
StyleGenerator<T>
getStyleGenerator()
Gets the style generator that is used for generating class names for rows.
protected void
internalSetDataProvider(DataProvider<T,?> dataProvider)
boolean
isColumnReorderingAllowed()
Returns whether column reordering is allowed.
boolean
isDetailsVisible(T item)
Returns the visibility of details component for given item.
boolean
isFooterVisible()
Gets the visibility of the Footer in this Grid.
boolean
isHeaderVisible()
Gets the visibility of the Header in this Grid.
boolean
isReadOnly()
Returns the read-only status from the state of this
AbstractComponent
.Iterator<Component>
iterator()
Gets an iterator to the collection of contained components.
FooterRow
prependFooterRow()
Adds a new row at the top of the footer section.
HeaderRow
prependHeaderRow()
Adds a new row at the top of the header section.
protected void
readData(org.jsoup.nodes.Element body, List<com.vaadin.ui.DeclarativeValueProvider<T>> providers)
Reads the declarative representation of a grid's data from the given element and stores it in the given
DeclarativeValueProvider
s.protected void
readItems(org.jsoup.nodes.Element design, DesignContext context)
Reads the data source items from the
design
.void
recalculateColumnWidths()
Requests that the column widths should be recalculated.
void
removeAllColumns()
Removes all columns from this Grid.
void
removeColumn(Grid.Column<T,?> column)
Removes the given column from this
Grid
.void
removeColumn(String columnId)
Removes the column with the given column id.
void
removeFooterRow(int index)
Removes the row at the given position from the footer section.
void
removeFooterRow(FooterRow row)
Removes the given row from the footer section.
void
removeHeaderRow(int index)
Removes the row at the given position from the header section.
void
removeHeaderRow(HeaderRow row)
Removes the given row from the header section.
void
scrollTo(int row)
Scrolls to a certain item, using
ScrollDestination.ANY
.void
scrollTo(int row, ScrollDestination destination)
Scrolls to a certain item, using user-specified scroll destination.
void
scrollToColumn(Grid.Column<T,?> column)
Scrolls to the given column, using
ScrollDestination.ANY
.void
scrollToColumn(Grid.Column<T,?> column, ScrollDestination destination)
Scrolls to the given column, using the given scroll destination.
void
scrollToColumn(String columnId)
Scrolls to the given column, using
ScrollDestination.ANY
.void
scrollToColumn(String columnId, ScrollDestination destination)
Scrolls to the given column, using the given scroll destination.
void
scrollToEnd()
Scrolls to the end of the last data row.
void
scrollToStart()
Scrolls to the beginning of the first data row.
void
select(T item)
This method is a shorthand that delegates to the currently set selection model.
protected void
setBeanType(Class<T> beanType)
Sets the bean type to use for property mapping.
protected void
setBeanType(String beanTypeClassName)
Sets the bean type to use for property mapping.
void
setBodyRowHeight(double rowHeight)
Sets the height of a body row.
protected void
setColumnId(String id, Grid.Column<T,?> 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(String... columnIds)
Sets a new column order for the grid based on their column ids.
void
setColumnReorderingAllowed(boolean columnReorderingAllowed)
Sets whether or not column reordering is allowed.
void
setColumnResizeMode(ColumnResizeMode mode)
Sets the column resize mode to use.
void
setColumns(String... columnIds)
Sets the columns and their order based on their column ids.
void
setColumns(Collection<String> columnIds)
Sets the columns and their order based on their column ids provided that collection supports preserving of the order.
void
setDataProvider(DataProvider<T,?> dataProvider)
Sets the data provider for this listing.
void
setDataProvider(Grid.FetchItemsCallback<T> fetchItems, SerializableSupplier<Integer> sizeCallback)
Sets a CallbackDataProvider using the given fetch items callback and a size callback.
void
setDefaultHeaderRow(HeaderRow row)
Sets the default row of the header.
void
setDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator)
Sets the description generator that is used for generating descriptions for rows.
void
setDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator, ContentMode contentMode)
Sets the description generator that is used for generating descriptions for rows.
void
setDetailsGenerator(DetailsGenerator<T> generator)
Sets the details component generator.
void
setDetailsVisible(T item, boolean visible)
Sets the visibility of details component for given item.
void
setFooterRowHeight(double rowHeight)
Sets the height of a footer row.
void
setFooterVisible(boolean footerVisible)
Sets the visibility of the Footer in this Grid.
void
setFrozenColumnCount(int numberOfColumns)
Sets the number of frozen columns in this grid.
void
setHeaderRowHeight(double rowHeight)
Sets the height of a header row.
void
setHeaderVisible(boolean headerVisible)
Sets the visibility of the Header in this Grid.
void
setHeight(float height, Sizeable.Unit unit)
Sets the height of the object.
void
setHeightByRows(double rows)
Sets the number of rows that should be visible in Grid's body.
void
setHeightMode(HeightMode heightMode)
Defines the mode in which the Grid widget's height is calculated.
protected void
setPropertySet(PropertySet<T> propertySet)
Sets the property set to use for this grid.
void
setReadOnly(boolean readOnly)
Sets the read-only status in the state of this
AbstractComponent
.void
setRowHeight(double rowHeight)
Sets the height of body, header and footer rows.
GridSelectionModel<T>
setSelectionMode(Grid.SelectionMode selectionMode)
Sets the grid's selection mode.
protected void
setSelectionModel(GridSelectionModel<T> model)
Sets the selection model for the grid.
void
setSidebarColumnOrder(GridConstants.SidebarColumnOrder order)
Set the order of the columns visible in the sidebar menu.
void
setSortOrder(GridSortOrderBuilder<T> builder)
Sets the sort order to use, given a
GridSortOrderBuilder
.void
setSortOrder(List<GridSortOrder<T>> order)
Sets the sort order to use.
void
setStyleGenerator(StyleGenerator<T> styleGenerator)
Sets the style generator that is used for generating class names for rows in this grid.
void
sort(Grid.Column<T,?> column)
Sort this Grid in ascending order by a specified column.
void
sort(Grid.Column<T,?> column, SortDirection direction)
Sort this Grid in user-specified direction by a column.
void
sort(String columnId)
Sort this Grid in ascending order by a specified column defined by id.
void
sort(String columnId, SortDirection direction)
Sort this Grid in a user-specified direction by a column defined by id.
static <BEAN> Grid<BEAN>
withPropertySet(PropertySet<BEAN> propertySet)
Creates a grid using a custom
PropertySet
implementation for creating a default set of columns and for resolving property names withaddColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.protected void
writeData(org.jsoup.nodes.Element body, DesignContext designContext)
Writes the data contained in this grid.
-
Methods inherited from class com.vaadin.ui.AbstractListing
addDataGenerator, focus, getDataCommunicator, getItemCaptionGenerator, getItemIconGenerator, getTabIndex, internalGetDataProvider, internalSetDataProvider, readDesign, readItem, removeDataGenerator, serializeDeclarativeRepresentation, setItemCaptionGenerator, setItemIconGenerator, setTabIndex, writeDesign, writeItem, writeItems
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setRequiredIndicatorVisible, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, readDesign, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible, writeDesign
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasDataProvider
setItems
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Constructor Detail
-
Grid
public Grid()
Creates a new grid without support for creating columns based on property names. Use an alternative constructor, such as
Grid(Class)
, to create a grid that automatically sets up columns based on the type of presented data.See Also:
-
Grid
public Grid(Class<T> beanType)
Creates a new grid that uses reflection based on the provided bean type to automatically set up an initial set of columns. All columns will be configured using the same
Object.toString()
renderer that is used byaddColumn(ValueProvider)
.Parameters:
beanType
- the bean type to use, notnull
See Also:
-
Grid
protected Grid(Class<T> beanType, DataCommunicator<T> dataCommunicator)
Creates a new grid that uses custom data communicator and provided bean type It uses reflection of the provided bean type to automatically set up an initial set of columns. All columns will be configured using the same
Object.toString()
renderer that is used byaddColumn(ValueProvider)
.Parameters:
beanType
- the bean type to use, notnull
dataCommunicator
- the data communicator to use, notnull
Since:
8.0.7
-
Grid
protected Grid(DataCommunicator<T> dataCommunicator)
Creates a new grid with the given data communicator and without support for creating columns based on property names.
Parameters:
dataCommunicator
- the custom data communicator to setSince:
8.0.7
See Also:
-
Grid
protected Grid(PropertySet<T> propertySet)
Creates a grid using a custom
PropertySet
implementation for configuring the initial columns and resolving property names foraddColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.Parameters:
propertySet
- the property set implementation to use, notnull
.See Also:
-
Grid
protected Grid(PropertySet<T> propertySet, DataCommunicator<T> dataCommunicator)
Creates a grid using a custom
PropertySet
implementation and custom data communicator.Property set is used for configuring the initial columns and resolving property names for
addColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.Parameters:
propertySet
- the property set implementation to use, notnull
.dataCommunicator
- the data communicator to use, notnull
Since:
8.0.7
See Also:
-
Grid
public Grid(String caption)
Creates a new
Grid
using the given caption.Parameters:
caption
- the caption of the grid
-
Grid
public Grid(String caption, DataProvider<T,?> dataProvider)
Creates a new
Grid
using the given caption andDataProvider
.Parameters:
caption
- the caption of the griddataProvider
- the data provider, notnull
-
Grid
public Grid(DataProvider<T,?> dataProvider)
Creates a new
Grid
using the givenDataProvider
.Parameters:
dataProvider
- the data provider, notnull
-
Grid
public Grid(String caption, Collection<T> items)
Creates a new
Grid
using the given caption and collection of items.Parameters:
caption
- the caption of the griditems
- the data items to use, notnull
-
-
Method Detail
-
beforeClientResponse
public void beforeClientResponse(boolean initial)
Description copied from interface:
ClientConnector
Called before the shared state and RPC invocations are sent to the client. Gives the connector an opportunity to set computed/dynamic state values or to invoke last minute RPC methods depending on other component features.
Specified by:
beforeClientResponse
in interfaceClientConnector
Overrides:
beforeClientResponse
in classAbstractComponent
Parameters:
initial
-true
if the client-side connector will be created and initialized after this method has been invoked.false
if there is already an initialized client-side connector.
-
setPropertySet
protected void setPropertySet(PropertySet<T> propertySet)
Sets the property set to use for this grid. Does not create or update columns in any way but will delete and re-create the editor.
This is only meant to be called from constructors and readDesign, at a stage where it does not matter if you throw away the editor.
Parameters:
propertySet
- the property set to useSince:
8.0.3
-
getPropertySet
protected PropertySet<T> getPropertySet()
Returns the property set used by this grid.
Returns:
propertySet the property set to return
Since:
8.4
-
withPropertySet
public static <BEAN> Grid<BEAN> withPropertySet(PropertySet<BEAN> propertySet)
Creates a grid using a custom
PropertySet
implementation for creating a default set of columns and for resolving property names withaddColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.This functionality is provided as static method instead of as a public constructor in order to make it possible to use a custom property set without creating a subclass while still leaving the public constructors focused on the common use cases.
Type Parameters:
BEAN
- the grid bean typeParameters:
propertySet
- the property set implementation to use, notnull
.Returns:
a new grid using the provided property set, not
null
See Also:
-
getBeanType
public Class<T> getBeanType()
Gets the bean type used by this grid.
The bean type is used to automatically set up a column added using a property name.
Returns:
the used bean type or
null
if no bean type has been definedSince:
8.0.3
-
fireColumnVisibilityChangeEvent
public <V> void fireColumnVisibilityChangeEvent(Grid.Column<T,V> column, boolean hidden, boolean userOriginated)
Sends a
Grid.ColumnVisibilityChangeEvent
to all listeners.Type Parameters:
V
- the column value typeParameters:
column
- the column that changed its visibilityhidden
-true
if the column was hidden,false
if it became visibleuserOriginated
-true
if the event was triggered by an UI interaction,false
otherwise
-
addColumn
public Grid.Column<T,?> addColumn(String propertyName)
Adds a new column with the given property name. The column will use a
TextRenderer
. The value is converted to a String usingObject.toString()
. The property name will be used as thecolumn id
and thecolumn caption
will be set based on the property definition.This method can only be used for a
Grid
created usingGrid(Class)
orwithPropertySet(PropertySet)
.You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
Parameters:
propertyName
- the property name of the new column, notnull
Returns:
the newly added column, not
null
-
addColumn
public Grid.Column<T,?> addColumn(String propertyName, AbstractRenderer<? super T,?> renderer)
Adds a new column with the given property name and renderer. The property name will be used as the
column id
and thecolumn caption
will be set based on the property definition.This method can only be used for a
Grid
created usingGrid(Class)
orwithPropertySet(PropertySet)
.You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
Parameters:
propertyName
- the property name of the new column, notnull
renderer
- the renderer to use, notnull
Returns:
the newly added column, not
null
-
addColumn
public Grid.Column<T,?> addColumn(String propertyName, AbstractRenderer<? super T,?> renderer, Grid.Column.NestedNullBehavior nestedNullBehavior)
Adds a new column with the given property name and renderer. The property name will be used as the
column id
and thecolumn caption
will be set based on the property definition.This method can only be used for a
Grid
created usingGrid(Class)
orwithPropertySet(PropertySet)
.You can add columns for nested properties with dot notation, eg.
"property.nestedProperty"
Parameters:
propertyName
- the property name of the new column, notnull
renderer
- the renderer to use, notnull
nestedNullBehavior
- the behavior whenReturns:
the newly added column, not
null
Since:
8.8
-
addColumn
public <V> Grid.Column<T,V> addColumn(ValueProvider<T,V> valueProvider)
Adds a new text column to this
Grid
with a value provider. The column will use aTextRenderer
. The value is converted to a String usingObject.toString()
. In-memory sorting will use the natural ordering of elements if they are mutually comparable and otherwise fall back to comparing the string representations of the values.Type Parameters:
V
- the column value typeParameters:
valueProvider
- the value providerReturns:
the new column
-
addColumn
public <V> Grid.Column<T,V> addColumn(ValueProvider<T,V> valueProvider, AbstractRenderer<? super T,? super V> renderer)
Adds a new column to this
Grid
with typed renderer and value provider.Type Parameters:
V
- the column value typeParameters:
valueProvider
- the value providerrenderer
- the column value rendererReturns:
the new column
See Also:
-
addColumn
public <V> Grid.Column<T,V> addColumn(ValueProvider<T,V> valueProvider, ValueProvider<V,String> presentationProvider)
Adds a new column to this
Grid
with value provider and presentation provider.Note: The presentation type for this method is set to be String. To use any custom renderer with the presentation provider, use
addColumn(ValueProvider, ValueProvider, AbstractRenderer)
.Type Parameters:
V
- the column value typeParameters:
valueProvider
- the value providerpresentationProvider
- the value presentation providerReturns:
the new column
Since:
8.1
See Also:
-
addColumn
public <V,P> Grid.Column<T,V> addColumn(ValueProvider<T,V> valueProvider, ValueProvider<V,P> presentationProvider, AbstractRenderer<? super T,? super P> renderer)
Adds a new column to this
Grid
with value provider, presentation provider and typed renderer.The presentation provider is a method that takes the value from the value provider, and maps that to a value that the renderer accepts. This feature can be used for storing a complex value in a column for editing, but providing a simplified presentation for the user when not editing.
Type Parameters:
V
- the column value typeP
- the column presentation typeParameters:
valueProvider
- the value providerpresentationProvider
- the value presentation providerrenderer
- the column value rendererReturns:
the new column
Since:
8.1
See Also:
-
addComponentColumn
public <V extends Component> Grid.Column<T,V> addComponentColumn(ValueProvider<T,V> componentProvider)
Adds a column that shows components.
This is a shorthand for
addColumn(String)
and its variants with aComponentRenderer
.Type Parameters:
V
- the column value type, extends componentParameters:
componentProvider
- a value provider that will return a component for the given itemReturns:
the new column
Since:
8.1
-
createColumn
protected <V,P> Grid.Column<T,V> createColumn(ValueProvider<T,V> valueProvider, ValueProvider<V,P> presentationProvider, AbstractRenderer<? super T,? super P> renderer)
Creates a column instance from a value provider, presentation provider and a renderer.
Type Parameters:
V
- the column value typeP
- the column presentation typeParameters:
valueProvider
- the value providerpresentationProvider
- the presentation providerrenderer
- the rendererReturns:
a new column instance
Since:
8.1
-
removeColumn
public void removeColumn(Grid.Column<T,?> column)
Removes the given column from this
Grid
. Note: If you have Editor with binding in this Grid to this property, you need to remove that using removeBinding method provided by Binder.Parameters:
column
- the column to removeThrows:
IllegalArgumentException
- if the column is not a valid one
-
removeColumn
public void removeColumn(String columnId)
Removes the column with the given column id.
Parameters:
columnId
- the id of the column to remove, notnull
See Also:
-
removeAllColumns
public void removeAllColumns()
Removes all columns from this Grid.
Since:
8.0.2
-
setSidebarColumnOrder
public void setSidebarColumnOrder(GridConstants.SidebarColumnOrder order)
Set the order of the columns visible in the sidebar menu. Order defaults to
GridConstants.SidebarColumnOrder.DEFAULT
, i.e. "present column list in the order they were added".Parameters:
order
- new ordering modeSince:
8.25
-
getSidebarColumnOrder
public GridConstants.SidebarColumnOrder getSidebarColumnOrder()
Get the current sidebar column order. Order defaults to
GridConstants.SidebarColumnOrder.DEFAULT
, i.e. "present column list in the order they were added".Returns:
a
GridConstants.SidebarColumnOrder
value
-
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.
Since:
8.1.1
-
setDetailsGenerator
public void setDetailsGenerator(DetailsGenerator<T> generator)
Sets the details component generator.
Parameters:
generator
- the generator for details components
-
setDetailsVisible
public void setDetailsVisible(T item, boolean visible)
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
-
isDetailsVisible
public boolean isDetailsVisible(T item)
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
-
getColumns
public List<Grid.Column<T,?>> getColumns()
Gets an unmodifiable collection of all columns currently in this
Grid
.Returns:
unmodifiable collection of columns
-
getColumn
public Grid.Column<T,?> getColumn(String columnId)
Gets a
Grid.Column
of this grid by its identifying string. When you use the Grid constructor with bean class, the columns are initialised with columnId being the property name.Parameters:
columnId
- the identifier of the column to getReturns:
the column corresponding to the given column identifier, or
null
if there is no such columnSee Also:
-
iterator
public Iterator<Component> iterator()
Gets an iterator to the collection of contained components. Using this iterator it is possible to step through all components contained in this container.
The iterator is typically unmodifiable, and calls to
Iterator.remove()
throw an exception.Note that the order of the returned components it not specified.
Specified by:
iterator
in interfaceHasComponents
Specified by:
iterator
in interfaceIterable<T>
Returns:
the component iterator.
-
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.
NOTE: this count includes
hidden columns
in the count.The default value is 0.
Parameters:
numberOfColumns
- the number of columns that should be frozenThrows:
IllegalArgumentException
- if the column count is less than -1 or greater than 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 columns
in the count.Returns:
the number of frozen columns
See Also:
-
setHeightByRows
public void setHeightByRows(double rows)
Sets the number of rows that should be visible in Grid's body. This method will set the height mode to be
HeightMode.ROW
.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.Throws:
IllegalArgumentException
- ifrows
is zero or lessIllegalArgumentException
- ifrows
isinfinite
IllegalArgumentException
- ifrows
isNaN
-
getHeightByRows
public double getHeightByRows()
Gets the amount of rows in Grid's body that are shown, while
getHeightMode()
isHeightMode.ROW
.Returns:
the amount of rows that are being shown in Grid's body
See Also:
-
setHeight
public void setHeight(float height, Sizeable.Unit unit)
Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
Note: This method will set the height mode to be
HeightMode.CSS
.Specified by:
setHeight
in interfaceSizeable
Overrides:
setHeight
in classAbstractComponent
Parameters:
height
- the height of the object.unit
- the unit used for the width.See Also:
-
setHeightMode
public void setHeightMode(HeightMode heightMode)
Defines the mode in which the Grid widget's height is calculated.
If
HeightMode.CSS
is given, Grid will respect the values given via asetHeight
-method, and behave as a traditional Component.If
HeightMode.ROW
is given, Grid will make sure that the body will display as many rows asgetHeightByRows()
defines. Note: If headers/footers are inserted or removed, the widget will resize itself to still display the required amount of rows in its body. It also takes the horizontal scrollbar into account.Parameters:
heightMode
- the mode in to which Grid should be set
-
getHeightMode
public HeightMode getHeightMode()
Returns the current
HeightMode
the Grid is in.Defaults to
HeightMode.CSS
.Returns:
the current HeightMode
-
setRowHeight
public void setRowHeight(double rowHeight)
Sets the height of body, header and footer rows. If -1 (default), the row height is calculated based on the theme for an empty row before the Grid is displayed.
Note that all header, body and footer rows get the same height if explicitly set. In automatic mode, each section is calculated separately based on an empty row of that type.
Parameters:
rowHeight
- The height of a row in pixels or -1 for automatic calculationSee Also:
setBodyRowHeight(double)
,setHeaderRowHeight(double)
,setFooterRowHeight(double)
-
setBodyRowHeight
public void setBodyRowHeight(double rowHeight)
Sets the height of a body row. If -1 (default), the row height is calculated based on the theme for an empty row before the Grid is displayed.
Parameters:
rowHeight
- The height of a row in pixels or -1 for automatic calculationSince:
8.2
-
setHeaderRowHeight
public void setHeaderRowHeight(double rowHeight)
Sets the height of a header row. If -1 (default), the row height is calculated based on the theme for an empty row before the Grid is displayed.
Parameters:
rowHeight
- The height of a row in pixels or -1 for automatic calculationSince:
8.2
-
setFooterRowHeight
public void setFooterRowHeight(double rowHeight)
Sets the height of a footer row. If -1 (default), the row height is calculated based on the theme for an empty row before the Grid is displayed.
Parameters:
rowHeight
- The height of a row in pixels or -1 for automatic calculationSince:
8.2
-
getRowHeight
@Deprecated public double getRowHeight()
Deprecated.replaced by three separate row height controlsReturns the current body row height.-1 if row height is in automatic calculation mode.
Returns:
body row height
See Also:
getBodyRowHeight()
,getHeaderRowHeight()
,getFooterRowHeight()
-
getBodyRowHeight
public double getBodyRowHeight()
Returns the current body row height. -1 if row height is in automatic calculation mode.
Returns:
body row height
Since:
8.2
-
getHeaderRowHeight
public double getHeaderRowHeight()
Returns the current header row height. -1 if row height is in automatic calculation mode.
Returns:
header row height
Since:
8.2
-
getFooterRowHeight
public double getFooterRowHeight()
Returns the current footer row height. -1 if row height is in automatic calculation mode.
Returns:
footer row height
Since:
8.2
-
setStyleGenerator
public void setStyleGenerator(StyleGenerator<T> styleGenerator)
Sets the style generator that is used for generating class names for rows in this grid. Returning null from the generator results in no custom style name being set. Note: The style generator is applied only to the body cells, not to the Editor.
Parameters:
styleGenerator
- the row style generator to set, not nullThrows:
NullPointerException
- ifstyleGenerator
isnull
See Also:
-
getStyleGenerator
public StyleGenerator<T> getStyleGenerator()
Gets the style generator that is used for generating class names for rows.
Returns:
the row style generator
See Also:
-
setDescriptionGenerator
public void setDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator)
Sets the description generator that is used for generating descriptions for rows. This method uses the
ContentMode.PREFORMATTED
content mode.Parameters:
descriptionGenerator
- the row description generator to set, ornull
to remove a previously set generatorSee Also:
-
setDescriptionGenerator
public void setDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator, ContentMode contentMode)
Sets the description generator that is used for generating descriptions for rows. This method uses the given content mode.
Parameters:
descriptionGenerator
- the row description generator to set, ornull
to remove a previously set generatorcontentMode
- the content mode for row tooltipsSince:
8.2
See Also:
-
getDescriptionGenerator
public DescriptionGenerator<T> getDescriptionGenerator()
Gets the description generator that is used for generating descriptions for rows.
Returns:
the row description generator, or
null
if no generator is set
-
getHeaderRow
public HeaderRow getHeaderRow(int index)
Returns the header row at the given index.
Parameters:
index
- the index of the row, where the topmost row has index zeroReturns:
the header row at the index
Throws:
IndexOutOfBoundsException
- ifrowIndex < 0 || rowIndex >= getHeaderRowCount()
-
getHeaderRowCount
public int getHeaderRowCount()
Gets the number of rows in the header section.
Returns:
the number of header rows
-
addHeaderRowAt
public HeaderRow addHeaderRowAt(int index)
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). Inserting at
getHeaderRowCount()
appends the row at the bottom of the header.Parameters:
index
- the index at which to insert the row, where the topmost row has index zeroReturns:
the inserted header row
Throws:
IndexOutOfBoundsException
- ifrowIndex < 0 || rowIndex > getHeaderRowCount()
See Also:
appendHeaderRow()
,prependHeaderRow()
,removeHeaderRow(HeaderRow)
,removeHeaderRow(int)
-
appendHeaderRow
public HeaderRow appendHeaderRow()
Adds a new row at the bottom of the header section.
Returns:
the appended header row
See Also:
prependHeaderRow()
,addHeaderRowAt(int)
,removeHeaderRow(HeaderRow)
,removeHeaderRow(int)
-
prependHeaderRow
public HeaderRow prependHeaderRow()
Adds a new row at the top of the header section.
Returns:
the prepended header row
See Also:
appendHeaderRow()
,addHeaderRowAt(int)
,removeHeaderRow(HeaderRow)
,removeHeaderRow(int)
-
removeHeaderRow
public void removeHeaderRow(HeaderRow row)
Removes the given row from the header section. Removing a default row sets the Grid to have no default row.
Parameters:
row
- the header row to be removed, not nullThrows:
IllegalArgumentException
- if the header does not contain the rowSee Also:
removeHeaderRow(int)
,addHeaderRowAt(int)
,appendHeaderRow()
,prependHeaderRow()
-
removeHeaderRow
public void removeHeaderRow(int index)
Removes the row at the given position from the header section.
Parameters:
index
- the index of the row to remove, where the topmost row has index zeroThrows:
IndexOutOfBoundsException
- ifindex < 0 || index >= getHeaderRowCount()
See Also:
removeHeaderRow(HeaderRow)
,addHeaderRowAt(int)
,appendHeaderRow()
,prependHeaderRow()
-
setHeaderVisible
public void setHeaderVisible(boolean headerVisible)
Sets the visibility of the Header in this Grid.
Parameters:
headerVisible
-true
if visible;false
if notSince:
8.1.1
-
isHeaderVisible
public boolean isHeaderVisible()
Gets the visibility of the Header in this Grid.
Returns:
true
if visible;false
if notSince:
8.1.1
-
getDefaultHeaderRow
public HeaderRow getDefaultHeaderRow()
Returns the current default row of the header.
Returns:
the default row or null if no default row set
See Also:
-
setDefaultHeaderRow
public void setDefaultHeaderRow(HeaderRow row)
Sets the default row of the header. The default row is a special header row that displays column captions and sort indicators. By default Grid has a single row which is also the default row. When a header row is set as the default row, any existing cell content is replaced by the column captions.
Parameters:
row
- the new default row, or null for no default rowThrows:
IllegalArgumentException
- if the header does not contain the row
-
getHeader
protected Header getHeader()
Returns the header section of this grid. The default header contains a single row, set as the default row.
Returns:
the header section
-
getFooterRow
public FooterRow getFooterRow(int index)
Returns the footer row at the given index.
Parameters:
index
- the index of the row, where the topmost row has index zeroReturns:
the footer row at the index
Throws:
IndexOutOfBoundsException
- ifrowIndex < 0 || rowIndex >= getFooterRowCount()
-
getFooterRowCount
public int getFooterRowCount()
Gets the number of rows in the footer section.
Returns:
the number of footer rows
-
addFooterRowAt
public FooterRow addFooterRowAt(int index)
Inserts a new row at the given position to the footer section. Shifts the row currently at that position and any subsequent rows down (adds one to their indices). Inserting at
getFooterRowCount()
appends the row at the bottom of the footer.Parameters:
index
- the index at which to insert the row, where the topmost row has index zeroReturns:
the inserted footer row
Throws:
IndexOutOfBoundsException
- ifrowIndex < 0 || rowIndex > getFooterRowCount()
See Also:
appendFooterRow()
,prependFooterRow()
,removeFooterRow(FooterRow)
,removeFooterRow(int)
-
appendFooterRow
public FooterRow appendFooterRow()
Adds a new row at the bottom of the footer section.
Returns:
the appended footer row
See Also:
prependFooterRow()
,addFooterRowAt(int)
,removeFooterRow(FooterRow)
,removeFooterRow(int)
-
prependFooterRow
public FooterRow prependFooterRow()
Adds a new row at the top of the footer section.
Returns:
the prepended footer row
See Also:
appendFooterRow()
,addFooterRowAt(int)
,removeFooterRow(FooterRow)
,removeFooterRow(int)
-
removeFooterRow
public void removeFooterRow(FooterRow row)
Removes the given row from the footer section. Removing a default row sets the Grid to have no default row.
Parameters:
row
- the footer row to be removed, not nullThrows:
IllegalArgumentException
- if the footer does not contain the rowSee Also:
removeFooterRow(int)
,addFooterRowAt(int)
,appendFooterRow()
,prependFooterRow()
-
removeFooterRow
public void removeFooterRow(int index)
Removes the row at the given position from the footer section.
Parameters:
index
- the index of the row to remove, where the topmost row has index zeroThrows:
IndexOutOfBoundsException
- ifindex < 0 || index >= getFooterRowCount()
See Also:
removeFooterRow(FooterRow)
,addFooterRowAt(int)
,appendFooterRow()
,prependFooterRow()
-
setFooterVisible
public void setFooterVisible(boolean footerVisible)
Sets the visibility of the Footer in this Grid.
Parameters:
footerVisible
-true
if visible;false
if notSince:
8.1.1
-
isFooterVisible
public boolean isFooterVisible()
Gets the visibility of the Footer in this Grid.
Returns:
true
if visible;false
if notSince:
8.1.1
-
getFooter
protected Footer getFooter()
Returns the footer section of this grid.
Returns:
the footer section
-
addColumnReorderListener
public Registration addColumnReorderListener(ColumnReorderListener listener)
Registers a new column reorder listener.
Parameters:
listener
- the listener to register, not nullReturns:
a registration for the listener
-
addColumnResizeListener
public Registration addColumnResizeListener(ColumnResizeListener listener)
Registers a new column resize listener.
Parameters:
listener
- the listener to register, not nullReturns:
a registration for the listener
-
addItemClickListener
public Registration addItemClickListener(ItemClickListener<? super T> listener)
Adds an item click listener. The listener is called when an item of this
Grid
is clicked.Parameters:
listener
- the item click listener, not nullReturns:
a registration for the listener
See Also:
addContextClickListener(com.vaadin.event.ContextClickEvent.ContextClickListener)
-
addContextClickListener
public Registration addContextClickListener(ContextClickEvent.ContextClickListener listener)
Adds a context click listener that gets notified when a context click happens.
Specified by:
addContextClickListener
in interfaceContextClickEvent.ContextClickNotifier
Overrides:
addContextClickListener
in classAbstractComponent
Parameters:
listener
- the context click listener to add, not null actual event provided to the listener isGrid.GridContextClickEvent
Returns:
a registration object for removing the listener
Since:
8.1
See Also:
addItemClickListener(com.vaadin.ui.components.grid.ItemClickListener<? super T>)
,Registration
-
addColumnVisibilityChangeListener
public Registration addColumnVisibilityChangeListener(ColumnVisibilityChangeListener listener)
Registers a new column visibility change listener.
Parameters:
listener
- the listener to register, not nullReturns:
a registration for the listener
-
isColumnReorderingAllowed
public boolean 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
-
setColumns
public void setColumns(String... columnIds)
Sets the columns and their order based on their column ids. Columns currently in this grid that are not present in the list of column ids are removed. This includes any column that has no id. Similarly, any new column in columns will be added to this grid. New columns can only be added for a
Grid
created usingGrid(Class)
orwithPropertySet(PropertySet)
.Parameters:
columnIds
- the column ids to setSee Also:
-
setColumns
public void setColumns(Collection<String> columnIds)
Sets the columns and their order based on their column ids provided that collection supports preserving of the order. Columns currently in this grid that are not present in the collection of column ids are removed. This includes any column that has no id. Similarly, any new column in columns will be added to this grid. New columns can only be added for a
Grid
created usingGrid(Class)
orwithPropertySet(PropertySet)
.Parameters:
columnIds
- the column ids to setSee Also:
-
setColumnOrder
public void setColumnOrder(Grid.Column<T,?>... columns)
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:
columns
- the columns in the order they should be
-
setColumnOrder
public void setColumnOrder(String... columnIds)
Sets a new column order for the grid based on their column ids. All columns which are not ordered here will remain in the order they were before as the last columns of grid.
Parameters:
columnIds
- the column ids in the order they should beSee Also:
-
getSelectionModel
public GridSelectionModel<T> getSelectionModel()
Returns the selection model for this grid.
Returns:
the selection model, not null
-
asSingleSelect
public GridSingleSelect<T> asSingleSelect()
Use this grid as a single select in
Binder
.Throws
IllegalStateException
if the grid is not using aSingleSelectionModel
.Returns:
the single select wrapper that can be used in binder
Throws:
IllegalStateException
- if not using a single selection model
-
getEditor
public Editor<T> getEditor()
Returns the
Editor
for this grid.Returns:
the editor, not null
-
asMultiSelect
public GridMultiSelect<T> asMultiSelect()
User this grid as a multiselect in
Binder
.Throws
IllegalStateException
if the grid is not using aMultiSelectionModel
.Returns:
the multiselect wrapper that can be used in binder
Throws:
IllegalStateException
- if not using a multiselection model
-
setSelectionModel
protected void setSelectionModel(GridSelectionModel<T> model)
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
SingleSelectionModelImpl
.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
See Also:
-
setSelectionMode
public GridSelectionModel<T> setSelectionMode(Grid.SelectionMode selectionMode)
Sets the grid's selection mode.
The built-in selection models are:Grid.SelectionMode.SINGLE
->SingleSelectionModelImpl
, the default modelGrid.SelectionMode.MULTI
->MultiSelectionModelImpl
, with checkboxes in the first column for selectionGrid.SelectionMode.NONE
->NoSelectionModel
, preventing selection
To use your custom selection model, you can use
setSelectionModel(GridSelectionModel)
, see existing selection model implementations for example.Parameters:
selectionMode
- the selection mode to switch to, notnull
Returns:
the used selection model
See Also:
Grid.SelectionMode
,GridSelectionModel
,setSelectionModel(GridSelectionModel)
-
getSelectedItems
public Set<T> getSelectedItems()
This method is a shorthand that delegates to the currently set selection model.
Returns:
the items in the current selection, not null
See Also:
-
select
public void select(T item)
This method is a shorthand that delegates to the currently set selection model.
Parameters:
item
- the item to select, not nullSee Also:
-
deselect
public void deselect(T item)
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:
-
addSelectionListener
public Registration addSelectionListener(SelectionListener<T> listener) throws UnsupportedOperationException
Adds a selection listener to the current selection model.
NOTE: If selection mode is switched with
setSelectionMode(SelectionMode)
, then this listener is not triggered anymore when selection changes!This is a shorthand for
grid.getSelectionModel().addSelectionListener()
. To get more detailed selection events, usegetSelectionModel()
and eitherSingleSelectionModel.addSingleSelectionListener(SingleSelectionListener)
orMultiSelectionModel.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
-
sort
public void sort(Grid.Column<T,?> column)
Sort this Grid in ascending order by a specified column.
Parameters:
column
- a column to sort against
-
sort
public void sort(Grid.Column<T,?> column, SortDirection direction)
Sort this Grid in user-specified direction by a column.
Parameters:
column
- a column to sort againstdirection
- a sort order value (ascending/descending)
-
sort
public void sort(String columnId)
Sort this Grid in ascending order by a specified column defined by id.
Parameters:
columnId
- the id of the column to sort againstSee Also:
-
sort
public void sort(String columnId, SortDirection direction)
Sort this Grid in a user-specified direction by a column defined by id.
Parameters:
columnId
- the id of the column to sort againstdirection
- a sort order value (ascending/descending)See Also:
-
clearSortOrder
public void clearSortOrder()
Clear the current sort order, and re-sort the grid.
-
setSortOrder
public void setSortOrder(List<GridSortOrder<T>> order)
Sets the sort order to use.
Parameters:
order
- a sort order list.Throws:
IllegalArgumentException
- if order is null
-
setSortOrder
public void setSortOrder(GridSortOrderBuilder<T> builder)
Sets the sort order to use, given a
GridSortOrderBuilder
. Shorthand forsetSortOrder(builder.build())
.Parameters:
builder
- the sort builder to retrieve the sort order fromThrows:
NullPointerException
- if builder is nullSee Also:
-
addSortListener
public Registration addSortListener(SortEvent.SortListener<GridSortOrder<T>> listener)
Adds a sort order change listener that gets notified when the sort order changes.
Specified by:
addSortListener
in interfaceSortEvent.SortNotifier<T>
Parameters:
listener
- the sort order change listener to addReturns:
a registration object for removing the listener
-
getSortOrder
public List<GridSortOrder<T>> getSortOrder()
Get the current sort order list.
Returns:
a sort order list
-
scrollTo
public void scrollTo(int row) throws IllegalArgumentException
Scrolls to a certain item, using
ScrollDestination.ANY
.If the item has an open details row, its size will also be taken into account.
Parameters:
row
- zero based index of the item to scroll to in the current view.Throws:
IllegalArgumentException
- if the provided row is outside the item range
-
scrollTo
public void scrollTo(int row, ScrollDestination destination)
Scrolls to a certain item, using user-specified scroll destination.
If the item has an open details row, its size will also be taken into account.
Parameters:
row
- zero based index of the item to scroll to in the current view.destination
- value specifying desired position of scrolled-to row, notnull
Throws:
IllegalArgumentException
- if the provided row is outside the item range
-
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.
-
scrollToColumn
public void scrollToColumn(String columnId)
Scrolls to the given column, using
ScrollDestination.ANY
.Parameters:
columnId
- the id of the column, notnull
Throws:
IllegalArgumentException
- if there is no column with the given idSince:
8.18
-
scrollToColumn
public void scrollToColumn(String columnId, ScrollDestination destination)
Scrolls to the given column, using the given scroll destination.
Parameters:
columnId
- the id of the column, notnull
destination
- value specifying desired position of scrolled-to column, notnull
Throws:
IllegalArgumentException
- if there is no column with the given idSince:
8.18
-
scrollToColumn
public void scrollToColumn(Grid.Column<T,?> column)
Scrolls to the given column, using
ScrollDestination.ANY
.Parameters:
column
- the column to scroll to, notnull
Since:
8.18
-
scrollToColumn
public void scrollToColumn(Grid.Column<T,?> column, ScrollDestination destination)
Scrolls to the given column, using the given scroll destination.
Parameters:
column
- the column to scroll to, notnull
destination
- value specifying desired position of scrolled-to column, notnull
Since:
8.18
-
getState
protected GridState getState()
Description copied from class:
AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().
Overrides:
getState
in classAbstractListing<T>
Returns:
updated component shared state
-
getState
protected GridState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractListing<T>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
setColumnResizeMode
public void setColumnResizeMode(ColumnResizeMode mode)
Sets the column resize mode to use. The default mode is
ColumnResizeMode.ANIMATED
.Parameters:
mode
- a ColumnResizeMode valueSince:
7.7.5
-
getColumnResizeMode
public ColumnResizeMode getColumnResizeMode()
Returns the current column resize mode. The default mode is
ColumnResizeMode.ANIMATED
.Returns:
a ColumnResizeMode value
Since:
7.7.5
-
createEditor
protected Editor<T> 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
-
readItems
protected void readItems(org.jsoup.nodes.Element design, DesignContext context)
Description copied from class:
AbstractListing
Reads the data source items from the
design
.Specified by:
readItems
in classAbstractListing<T>
Parameters:
design
- The element to obtain the state fromcontext
- The DesignContext instance used for parsing the design
-
getDataProvider
public DataProvider<T,?> getDataProvider()
Description copied from interface:
HasItems
Returns the source of data items used by this listing.
Specified by:
getDataProvider
in interfaceHasItems<T>
Returns:
the data provider, not null
-
setDataProvider
public void setDataProvider(DataProvider<T,?> dataProvider)
Description copied from interface:
HasDataProvider
Sets the data provider for this listing. The data provider is queried for displayed items as needed.
Specified by:
setDataProvider
in interfaceHasDataProvider<T>
Parameters:
dataProvider
- the data provider, not null
-
setDataProvider
public void setDataProvider(Grid.FetchItemsCallback<T> fetchItems, SerializableSupplier<Integer> sizeCallback)
Sets a CallbackDataProvider using the given fetch items callback and a size callback.
This method is a shorthand for making a
CallbackDataProvider
that handles a partialQuery
object.Parameters:
fetchItems
- a callback for fetching itemssizeCallback
- a callback for getting the count of itemsSee Also:
-
doReadDesign
protected void doReadDesign(org.jsoup.nodes.Element design, DesignContext context)
Description copied from class:
AbstractListing
Reads the listing specific state from the given design.
This method is separated from
AbstractListing.readDesign(Element, DesignContext)
to be overridable in subclasses that need to replace this, but still must be able to callsuper.readDesign(...)
.Overrides:
doReadDesign
in classAbstractListing<T>
Parameters:
design
- The element to obtain the state fromcontext
- The DesignContext instance used for parsing the designSee Also:
-
setBeanType
protected void setBeanType(String beanTypeClassName)
Sets the bean type to use for property mapping.
This method is responsible also for setting or updating the property set so that it matches the given bean type.
Protected mostly for Designer needs, typically should not be overridden or even called.
Parameters:
beanTypeClassName
- the fully qualified class name of the bean typeSince:
8.0.3
-
setBeanType
protected void setBeanType(Class<T> beanType)
Sets the bean type to use for property mapping.
This method is responsible also for setting or updating the property set so that it matches the given bean type.
Protected mostly for Designer needs, typically should not be overridden or even called.
Parameters:
beanType
- the bean type classSince:
8.0.3
-
doWriteDesign
protected void doWriteDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Description copied from class:
AbstractListing
Writes listing specific state into the given design.
This method is separated from
AbstractListing.writeDesign(Element, DesignContext)
to be overridable in subclasses that need to replace this, but still must be able to callsuper.writeDesign(...)
.Overrides:
doWriteDesign
in classAbstractListing<T>
Parameters:
design
- The element to write the component state to. Any previous attributes or child nodes are not cleared.designContext
- The DesignContext instance used for writing the designSee Also:
-
deserializeDeclarativeRepresentation
protected T deserializeDeclarativeRepresentation(String item)
Description copied from class:
AbstractListing
Deserializes a string to a data item.
Default implementation is able to handle only
String
as an item type. There will be aClassCastException
ifT
is not aString
.Overrides:
deserializeDeclarativeRepresentation
in classAbstractListing<T>
Parameters:
item
- string to deserializeReturns:
deserialized item
See Also:
-
isReadOnly
public boolean isReadOnly()
Description copied from class:
AbstractComponent
Returns the read-only status from the state of this
AbstractComponent
. This method should be made public inComponents
that implementHasValue
.Overrides:
isReadOnly
in classAbstractComponent
Returns:
true
if state has read-only on;false
if notSee Also:
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from class:
AbstractComponent
Sets the read-only status in the state of this
AbstractComponent
. This method should be made public inComponents
that implementHasValue
.Overrides:
setReadOnly
in classAbstractComponent
Parameters:
readOnly
- a boolean value specifying whether the component is put read-only mode or not
-
readData
protected void readData(org.jsoup.nodes.Element body, List<com.vaadin.ui.DeclarativeValueProvider<T>> providers)
Reads the declarative representation of a grid's data from the given element and stores it in the given
DeclarativeValueProvider
s. Each member in the list of value providers corresponds to a column in the grid.Parameters:
body
- the element to read data fromproviders
- list ofDeclarativeValueProvider
s to store the data of each column toSince:
8.1
-
writeData
protected void writeData(org.jsoup.nodes.Element body, DesignContext designContext)
Writes the data contained in this grid. Used when serializing a grid to its declarative representation, if
DesignContext.shouldWriteData(Component)
returnstrue
for the grid that is being written.Parameters:
body
- the body element to write the declarative representation of data todesignContext
- the design contextSince:
8.1, 8.1
-
setColumnId
protected void setColumnId(String id, Grid.Column<T,?> column)
Sets a user-defined identifier for given column.
Parameters:
column
- the columnid
- the user-defined identifierSee Also:
-
getCustomAttributes
protected Collection<String> getCustomAttributes()
Description copied from class:
AbstractComponent
Returns a collection of attributes that should not be handled by the basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods. Typically these are handled in a custom way in the overridden versions of the above methodsOverrides:
getCustomAttributes
in classAbstractComponent
Returns:
the collection of attributes that are not handled by the basic implementation
-
getColumnByInternalId
protected Grid.Column<T,?> getColumnByInternalId(String columnId)
Returns a column identified by its internal id. This id should not be confused with the user-defined identifier.
Parameters:
columnId
- the internal id of columnReturns:
column identified by internal id
-
getInternalIdForColumn
protected String getInternalIdForColumn(Grid.Column<T,?> column)
Returns the internal id for given column. This id should not be confused with the user-defined identifier.
Parameters:
column
- the columnReturns:
internal id of given column
-
createSortingComparator
protected SerializableComparator<T> createSortingComparator()
Creates a comparator for grid to sort rows.
Returns:
the comparator based on column sorting information.
-
internalSetDataProvider
protected void internalSetDataProvider(DataProvider<T,?> dataProvider)
Overrides:
internalSetDataProvider
in classAbstractListing<T>
-
-